Skip to content

fix/auth-token #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: access_token expire time in cookie and jwt
  • Loading branch information
winverse committed Feb 14, 2024
commit 49d53427ef222302cce7a1f076f6b18445d763b5
2 changes: 1 addition & 1 deletion packages/velog-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"graphql-scalars": "^1.22.2",
"inquirer": "^9.2.12",
"ioredis": "^5.3.2",
"jsonwebtoken": "^9.0.0",
"jsonwebtoken": "^9.0.2",
"lru-cache": "^10.0.0",
"marked": "^8.0.0",
"mercurius": "^13.0.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/velog-server/src/common/plugins/global/authPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
fastify.decorateRequest('user', null)
fastify.addHook('preHandler', async (request, reply) => {
if (request.url.includes('/auth/logout')) return

let accessToken: string | undefined = request.cookies['access_token']
const refreshToken: string | undefined = request.cookies['refresh_token']
const authorization = request.headers['authorization']

try {
if (!accessToken && authorization) {
accessToken = authorization.split('Bearer ')[1]
Expand Down
4 changes: 2 additions & 2 deletions packages/velog-server/src/lib/jwt/JwtService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class JwtService {
},
{
subject: 'access_token',
expiresIn: '1h',
expiresIn: '24h',
},
)

Expand Down Expand Up @@ -100,7 +100,7 @@ export class JwtService {
},
{
subject: 'access_token',
expiresIn: '1h',
expiresIn: '24h',
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class SocialController implements Controller {
if (user) {
const tokens = await this.jwt.generateUserToken(user.id)
this.cookie.setCookie(reply, 'access_token', tokens.accessToken, {
maxAge: Time.ONE_HOUR_IN_MS,
maxAge: Time.ONE_HOUR_IN_MS * 24,
})
this.cookie.setCookie(reply, 'refresh_token', tokens.refreshToken, {
maxAge: Time.ONE_DAY_IN_MS * 30,
Expand Down Expand Up @@ -255,7 +255,7 @@ export class SocialController implements Controller {

const tokens = await this.jwt.generateUserToken(user.id)
this.cookie.setCookie(reply, 'access_token', tokens.accessToken, {
maxAge: Time.ONE_HOUR_IN_MS,
maxAge: Time.ONE_HOUR_IN_MS * 24,
})
this.cookie.setCookie(reply, 'refresh_token', tokens.refreshToken, {
maxAge: Time.ONE_DAY_IN_MS * 30,
Expand Down
2 changes: 1 addition & 1 deletion packages/velog-server/src/services/UserService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class UserService implements Service {
)

this.cookie.setCookie(ctx.reply, 'access_token', tokens.accessToken, {
maxAge: Time.ONE_HOUR_IN_MS,
maxAge: Time.ONE_HOUR_IN_MS * 24,
})
this.cookie.setCookie(ctx.reply, 'refresh_token', tokens.refreshToken, {
maxAge: Time.ONE_DAY_IN_MS * 30,
Expand Down