Skip to content

Commit bfb6d44

Browse files
chore: wip
1 parent a620b8e commit bfb6d44

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

storage/framework/core/auth/src/authentication.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ export class Auth {
104104
})
105105
.executeTakeFirst()
106106

107-
if (!result?.insertId)
107+
const insertId = Number(result?.insertId) || Number(result?.numInsertedOrUpdatedRows)
108+
109+
if (!insertId)
108110
throw new HttpError(500, 'Failed to create token')
109111

110112
// Encrypt the token ID using client secret
111-
const encryptedId = encrypt(result.insertId.toString(), clientSecret)
113+
const encryptedId = encrypt(insertId.toString(), clientSecret)
112114

113115
// Combine into final token format with JWT first
114116
return `${jwtToken}:${encryptedId}` as AuthToken

storage/framework/core/auth/src/register.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import type { NewUser } from '@stacksjs/orm'
22
import type { AuthToken } from './token'
33
import { db } from '@stacksjs/database'
4+
import { User } from '@stacksjs/orm'
45
import { makeHash } from '@stacksjs/security'
56
import { Auth } from './authentication'
67

78
export async function register(credentials: NewUser): Promise<{ token: AuthToken } | null> {
89
const { email, password, name } = credentials
910

1011
// Check if user already exists
11-
const existingUser = await db.selectFrom('users')
12-
.where('email', '=', email)
13-
.selectAll()
14-
.executeTakeFirst()
12+
const existingUser = await User.where('email', '=', email).first()
1513

1614
if (existingUser)
1715
return null
@@ -34,10 +32,7 @@ export async function register(credentials: NewUser): Promise<{ token: AuthToken
3432
return null
3533

3634
// Get the created user
37-
const user = await db.selectFrom('users')
38-
.where('id', '=', insertId)
39-
.selectAll()
40-
.executeTakeFirst()
35+
const user = await User.find(insertId)
4136

4237
if (!user)
4338
return null

0 commit comments

Comments
 (0)