forked from CRSS/Website
fix: remove session cookie if session is not found
This commit is contained in:
parent
77234531c5
commit
4880cfe613
|
@ -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);
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue