Skip to content

Commit

Permalink
fix: logout/login sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
aseerkt committed Jul 26, 2024
1 parent 07787a0 commit 3f10759
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion server/src/common/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const recreateAccessToken: RequestHandler = async (req, res) => {

const isValid = await isRefreshTokenValid(
refreshPayload.id,
refreshToken.tokenId,
refreshPayload.tokenId,
refreshToken,
)

Expand Down Expand Up @@ -74,6 +74,7 @@ export const logout: RequestHandler = async (req, res, next) => {
}
await invalidateRefreshToken(req.user!.id, refreshPayload.tokenId)
clearRefreshTokenCookie(res)
res.sendStatus(200)
} catch (error) {
next(error)
}
Expand Down
1 change: 1 addition & 0 deletions server/src/redis/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const isRefreshTokenValid = async (
redisKeys.USER_TOKEN(userId),
tokenId,
)
console.log('redis access token', redisToken, tokenId)
return redisToken === token
}

Expand Down
6 changes: 5 additions & 1 deletion server/src/redis/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { config } from '@/config'

if (!config.isProd) {
process.env.DEBUG = 'ioredis:*'
}

import Redis from 'ioredis'

let redisClient: Redis

export function getRedisClient() {
if (!redisClient) {
process.env.DEBUG = config.isProd ? '' : 'ioredis:*'
redisClient = new Redis({
host: config.redisHost,
port: +config.redisPort,
Expand Down
2 changes: 1 addition & 1 deletion web/src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useAuthSetter = () => {
}, [])

const clearAuth = useCallback(() => {
queryClient.setQueryData(['userToken'], () => undefined)
queryClient.setQueryData(['userToken'], () => null)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

Expand Down

0 comments on commit 3f10759

Please sign in to comment.