Skip to content

Commit

Permalink
fix: update user token generation and context logging
Browse files Browse the repository at this point in the history
- Enhanced the user token generation to include expiration (exp) and issued at (iat) timestamps for better token management.
- Updated the context creation function to log the token instead of the user agent, improving debugging information related to user authentication.

These changes improve the security and traceability of user sessions in the application.
  • Loading branch information
blinko-space committed Jan 14, 2025
1 parent 9693530 commit 66e321f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/server/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function createContext(
const ip = requestIp.getClientIp(opts.req);
const ua = opts.req.headers['user-agent'];
const userAgent = ua ? Bowser.parse(ua) : null;
console.log({ userAgent })
console.log({ token })
if (!token?.sub) {
return { ip, userAgent } as User;
}
Expand Down
2 changes: 2 additions & 0 deletions src/server/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const genToken = async ({ id, name, role }: { id: number, name: string, role: st
role,
name,
sub: id.toString(),
exp: Math.floor(Date.now() / 1000) + (60 * 60 * 24 * 365 * 100),
iat: Math.floor(Date.now() / 1000)
},
secret
})
Expand Down

0 comments on commit 66e321f

Please sign in to comment.