diff --git a/src/services/auth/jwt.ts b/src/services/auth/jwt.ts index 493ee96..737e6dc 100644 --- a/src/services/auth/jwt.ts +++ b/src/services/auth/jwt.ts @@ -18,15 +18,15 @@ export function buildLoginResponse( refreshToken: string, ): LoginResponse { return { - accessToken, - refreshToken, user: { id: user.id, nickname: user.nickname ?? null, avatarUrl: user.avatarUrl ?? null, tier: user.tier ?? 'free', - xpTotal: user.xpTotal ?? 0, - streakDays: user.streakDays ?? 0, + }, + tokens: { + accessToken, + refreshToken, }, }; } @@ -90,13 +90,7 @@ export async function findOrCreateHuawei( return buildLoginResponse(user, tokens.accessToken, tokens.refreshToken); } -export async function refreshJwt(app: FastifyInstance, refreshToken: string): Promise<{ accessToken: string }> { +export async function refreshJwt(app: FastifyInstance, refreshToken: string): Promise<{ accessToken: string; refreshToken: string }> { const decoded = app.jwt.verify(refreshToken); - const payload: JwtPayload = { - userId: decoded.userId, - authType: decoded.authType, - tier: decoded.tier, - }; - const accessToken = app.jwt.sign(payload, { expiresIn: '1h' }); - return { accessToken }; + return signTokens(app, decoded.userId, decoded.authType, decoded.tier ?? 'free'); } diff --git a/src/types/auth.ts b/src/types/auth.ts index b6f4023..34a8af2 100644 --- a/src/types/auth.ts +++ b/src/types/auth.ts @@ -8,15 +8,15 @@ export interface JwtPayload { } export interface LoginResponse { - accessToken: string; - refreshToken: string; user: { id: string; nickname: string | null; avatarUrl: string | null; tier: string; - xpTotal: number; - streakDays: number; + }; + tokens: { + accessToken: string; + refreshToken: string; }; }