diff --git a/client/src/components/AppHeader.tsx b/client/src/components/AppHeader.tsx
index e165a86..61cf05a 100644
--- a/client/src/components/AppHeader.tsx
+++ b/client/src/components/AppHeader.tsx
@@ -1,7 +1,8 @@
import logo from '@assets/images/logo.svg';
import { useQuery } from '@tanstack/react-query';
+import { useEffect, useState } from 'react';
import { Cookies, withCookies } from 'react-cookie';
-import { useNavigate } from 'react-router-dom';
+import { Navigate, useNavigate } from 'react-router-dom';
const getMeInfo = async () => {
const token = new Cookies().get('token');
@@ -16,8 +17,6 @@ const getMeInfo = async () => {
return response.json();
};
-
-
const AppHeader = () => {
const meInfo = useQuery(['me'], getMeInfo, {
onSuccess: (data) => {
@@ -28,6 +27,11 @@ const AppHeader = () => {
},
});
+ const logOut = async () => {
+ new Cookies().remove('token');
+ window.location.reload();
+ };
+
return (
@@ -43,7 +47,9 @@ const AppHeader = () => {
{meInfo.isLoading ? '' : meInfo.data ? meInfo.data.firstName + ' ' + meInfo.data.lastName : ''}
-
diff --git a/client/src/controllers/Auth.ts b/client/src/controllers/Auth.ts
index e15ac9b..41ad556 100644
--- a/client/src/controllers/Auth.ts
+++ b/client/src/controllers/Auth.ts
@@ -1,9 +1,8 @@
-import { useCookies } from "react-cookie";
+import { Cookies } from "react-cookie";
const checkAuth = () => {
- const [cookie, setCookie] = useCookies(['token']);
-
- if (cookie.token && cookie.token !== '') {
+ const token = new Cookies().get("token");
+ if (token && token !== '') {
return true;
}
return false;
diff --git a/client/src/routes/login.tsx b/client/src/routes/login.tsx
index e1b96ad..6cb6aff 100644
--- a/client/src/routes/login.tsx
+++ b/client/src/routes/login.tsx
@@ -1,4 +1,4 @@
-import { Link, Navigate } from 'react-router-dom';
+import { Link, Navigate, useNavigate } from 'react-router-dom';
import logo from '@assets/images/logo.svg';
import { useQuery } from '@tanstack/react-query';
import { useState } from 'react';
@@ -9,7 +9,7 @@ const Login = () => {
const [cookie, setCookie] = useCookies(['token']);
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
-
+
const { refetch } = useQuery(
['login'],
async () => {
@@ -25,8 +25,8 @@ const Login = () => {
},
{
onSuccess: (data: Token) => {
- setCookie('token', data.token, { path: '/', expires: new Date(data.expiresAt) });
- return
;
+ setCookie('token', data.token, { path: '/', expires: new Date(data.expiresAt), sameSite: 'strict' });
+ window.location.reload();
},
onError: (error) => {
console.error(error);