1
0
Fork 0
forked from CRSS/Website

fix: remove session cookie if session is not found

This commit is contained in:
TheClashFruit 2024-08-29 16:12:31 +02:00
parent 77234531c5
commit 4880cfe613
Signed by: TheClashFruit
GPG key ID: 09BB24C34C2F3204
2 changed files with 4 additions and 3 deletions

View file

@ -20,15 +20,16 @@ export const UserProvider = ({ children }: { children: React.ReactNode }) => {
const sessionCookie = getCookie('session');
if (sessionCookie) {
setIsLoggedIn(true);
try {
const res = await fetch('/api/v1/user/@me');
if (res.ok) {
const userData = await res.json();
setIsLoggedIn(true);
setUser(userData);
} else {
document.cookie = 'session=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT';
}
} catch (error) {
console.error('Error fetching user data:', error);

View file

@ -83,7 +83,7 @@ export default function Settings({ sessions }: { sessions: any[] }) {
{session.current ? (
<label>Current Session</label>
) : (
<button>Sign Out</button>
<button disabled>Sign Out</button>
)}
</td>
</tr>