Skip to content

Commit

Permalink
fix: 변수명으로 인한 token null값 덧씌움
Browse files Browse the repository at this point in the history
  • Loading branch information
halionaz committed Aug 21, 2024
1 parent 69a37bd commit f8ecba2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions libs/clients/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ export function AuthProvider() {
const { accessToken, refreshToken, clearTokens, setTokens } = useAuthStore();

const setTokenFromCookie = useCallback(() => {
let accessToken = null,
refreshToken = null;
let accessTokenFromCookie = null,
refreshTokenFromCookie = null;

document.cookie.split(';').forEach((c) => {
if (c.trim().startsWith('access-token=')) accessToken = c.split('=')[1];
if (c.trim().startsWith('refresh-token=')) refreshToken = c.split('=')[1];
if (c.trim().startsWith('access-token=')) accessTokenFromCookie = c.split('=')[1];
if (c.trim().startsWith('refresh-token=')) refreshTokenFromCookie = c.split('=')[1];
});
console.log(`access: ${accessToken}`);
console.log(`refresh: ${refreshToken}`);
if (!accessToken || !refreshToken) {
console.log(`access: ${accessTokenFromCookie}`);
console.log(`refresh: ${refreshTokenFromCookie}`);
if (!accessTokenFromCookie || !refreshTokenFromCookie) {
clearTokens();
return false;
}

document.cookie = 'access-token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
document.cookie = 'refresh-token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';

setTokens(accessToken, refreshToken);
setTokens(accessTokenFromCookie, refreshTokenFromCookie);

return true;
}, [clearTokens, setTokens]);
Expand Down

0 comments on commit f8ecba2

Please sign in to comment.