refactor(auth): streamline logout route and update route tree for logout integration
This commit is contained in:
+12
-16
@@ -91,22 +91,18 @@ export async function authRoutes(app: FastifyInstance): Promise<void> {
|
||||
},
|
||||
})
|
||||
|
||||
app.post(
|
||||
'/api/v1/auth/logout',
|
||||
{ onRequest: requireAuth },
|
||||
async (request, reply) => {
|
||||
const cookie = request.headers.cookie ?? ''
|
||||
const match = cookie.match(new RegExp(`${REFRESH_COOKIE}=([^;]+)`))
|
||||
if (match?.[1]) {
|
||||
revokeRefreshSession(app.db, match[1])
|
||||
}
|
||||
reply.header(
|
||||
'Set-Cookie',
|
||||
`${REFRESH_COOKIE}=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0`,
|
||||
)
|
||||
return { ok: true }
|
||||
},
|
||||
)
|
||||
app.post('/api/v1/auth/logout', async (request, reply) => {
|
||||
const cookie = request.headers.cookie ?? ''
|
||||
const match = cookie.match(new RegExp(`${REFRESH_COOKIE}=([^;]+)`))
|
||||
if (match?.[1]) {
|
||||
revokeRefreshSession(app.db, match[1])
|
||||
}
|
||||
reply.header(
|
||||
'Set-Cookie',
|
||||
`${REFRESH_COOKIE}=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0`,
|
||||
)
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
app.get(
|
||||
'/api/v1/auth/me',
|
||||
|
||||
Reference in New Issue
Block a user