Skip to content

Commit

Permalink
fix login
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed Mar 5, 2024
1 parent a610d07 commit d349d28
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/server/backend/$base/server/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export abstract class SessionProvider<TSession extends Session<string>> {
...data,
lastSeen: new Date(),
} as TSession

await this.store.set(sessionId, _session)
return sessionId
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'node:buffer'
import type { Buffer } from 'node:buffer'
import type { Document } from 'bson'
import * as BSON from 'bson'
import { commandOptions, type createClient } from 'redis'
Expand Down Expand Up @@ -50,8 +50,9 @@ export class RedisSessionStore<TDoc extends Document & Session<any>> extends Ses
}

async #set(key: KeyOf<TDoc>, value: TDoc) {
const stream = BSON.serialize(value)
await this.#redis.set(key, Buffer.from(stream.buffer), { EX: sessionConfig.expire / 1000 })
const stream = BSON.serialize(value, { ignoreUndefined: true })

await this.#redis.set(key, stream as Buffer, { EX: sessionConfig.expire / 1000 })
return key
}

Expand Down
5 changes: 3 additions & 2 deletions src/server/trpc/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const t = initTRPC.context<Context>().create({
errorFormatter(opts) {
const { shape, error } = opts
const eData = {
...(import.meta.dev ? shape.data : {}),
...(import.meta.dev ? shape.data : { code: shape.data.code }),
zodError:
(error.code === 'BAD_REQUEST' && error.cause instanceof ZodError)
? error.cause.flatten()
Expand All @@ -22,9 +22,10 @@ export const t = initTRPC.context<Context>().create({
delete eData[i as keyof typeof eData]
}
}

return {
...pick(shape, ['code', 'message']),
data: { ...eData },
data: eData,
}
},

Expand Down
8 changes: 2 additions & 6 deletions src/store/session.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { TRPCError } from '@trpc/server'
import md5 from 'md5'
import { defineStore } from 'pinia'
import type { UserFull } from '~/def/user'
Expand Down Expand Up @@ -71,11 +70,8 @@ export const useSession = defineStore('session', {
return true
}
catch (err) {
if (((err as any).data as TRPCError)?.code === 'NOT_FOUND') {
console.error('not-found')
this.$reset()
}

// TODO: fix err is empty
this.$reset()
return false
}
},
Expand Down

0 comments on commit d349d28

Please sign in to comment.