File tree Expand file tree Collapse file tree 2 files changed +5
-8
lines changed Expand file tree Collapse file tree 2 files changed +5
-8
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ model AuthToken {
3434 id Int @id @default (autoincrement () )
3535 created_at DateTime @default (now () )
3636 updated_at DateTime @updatedAt
37- user_id Int
37+ user_id Int @unique
3838 token String @unique
3939 user User @relation (fields : [user_id ] , references : [id ] )
4040}
Original file line number Diff line number Diff line change @@ -23,13 +23,10 @@ export const actions: Actions = {
2323
2424 if ( ! password_valid ) return invalid ( 400 , { credentials : true } )
2525
26- await db . authToken . deleteMany ( { where : { user_id : user . id } } )
27-
28- const auth_token = await db . authToken . create ( {
29- data : {
30- user_id : user . id ,
31- token : crypto . randomUUID ( ) ,
32- } ,
26+ const auth_token = await db . authToken . upsert ( {
27+ where : { user_id : user . id } ,
28+ update : { token : crypto . randomUUID ( ) } ,
29+ create : { user_id : user . id , token : crypto . randomUUID ( ) }
3330 } )
3431
3532 cookies . set ( 'session_id' , auth_token . token , {
You can’t perform that action at this time.
0 commit comments