Skip to content

Commit

Permalink
fix: cookie on client remove
Browse files Browse the repository at this point in the history
  • Loading branch information
iaurg committed Dec 8, 2023
1 parent 9c0b330 commit 3223d57
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
16 changes: 16 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@tanstack/react-query": "^4.36.1",
"@tanstack/react-query-devtools": "^4.36.1",
"axios": "^1.6.2",
"js-cookie": "^3.0.5",
"jwt-decode": "^4.0.0",
"konva": "^9.2.3",
"next": "^14.0.3",
Expand All @@ -30,6 +31,7 @@
"typescript": "^5.3.2"
},
"devDependencies": {
"@types/js-cookie": "^3.0.6",
"@types/node": "^20.10.3",
"@types/react": "^18.2.41",
"@types/react-dom": "^18.2.17",
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ export default function Header() {
<Trophy color="white" size={22} />
<span className="hidden sm:inline">Ranking</span>
</Link>
<Link
href="/"
<button
className="text-white font-bold rounded-lg transition-all hover:bg-purple42-200
flex items-center justify-center space-x-2 px-4 py-2"
onClick={() => signOut()}
title="Sair"
>
<SignOut color="white" size={22} />
<span className="hidden sm:inline">Sair</span>
</Link>
</button>
</div>
</div>
);
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use client";
import nookies from "nookies";
import Cookies from 'js-cookie';

import React, { createContext, useEffect, useState } from "react";
import { api } from "@/services/apiClient";
import { User } from "@/types/user";
Expand Down Expand Up @@ -29,8 +31,8 @@ export const AuthContext = createContext<AuthContextType>(
);

export function signOut() {
nookies.destroy(null, "accessToken");
nookies.destroy(null, "refreshToken");
Cookies.remove('accessToken');
Cookies.remove('refreshToken');
api.defaults.headers["Authorization"] = "";
window.location.replace("/");
}
Expand Down

0 comments on commit 3223d57

Please sign in to comment.