Skip to content

Commit

Permalink
fix: logout
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed Jun 3, 2020
1 parent d29e9e0 commit 74bef5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/hooks/useAuth.js
Expand Up @@ -50,16 +50,16 @@ export function useAuth() {
const { user, setUser } = useContext(AuthContext);
async function logout() {
setToken(null);
setUser(null);
try {
await request("/api/logout", {
credentials: "include",
mode: "same-origin",
});
setUser(null);
window.location.reload();
} catch (error) {
console.error("[ client logout ] failed", error);
}
window.location.reload();
}

const isAuth = Boolean(user);
Expand Down
4 changes: 3 additions & 1 deletion src/lib/auth.js
Expand Up @@ -51,6 +51,8 @@ async function refreshToken(ctx) {
setToken(tokenData);
} catch (error) {
console.error("[ auth.refreshToken error ]", { error });
console.log("[auth.refreshToken error]", token);
setToken(null);
if (ctx && ctx.res) {
ctx.res.writeHead(302, { Location: "/login" });
ctx.res.end();
Expand All @@ -65,7 +67,7 @@ async function refreshToken(ctx) {
}

function setToken(tokenData) {
token = { ...tokenData };
token = tokenData;
}

export { getToken, getUserId, isTokenExpired, refreshToken, setToken };

0 comments on commit 74bef5f

Please sign in to comment.