Вроде работает
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { auth } from '../../lib/auth/store';
|
||||
import { api } from '../../lib/api';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
// [SECTION: TEMPLATE]
|
||||
@@ -23,20 +24,8 @@
|
||||
if ($auth.token && !$auth.user) {
|
||||
auth.setLoading(true);
|
||||
try {
|
||||
const response = await fetch('/api/auth/me', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${$auth.token}`
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const user = await response.json();
|
||||
auth.setUser(user);
|
||||
} else {
|
||||
// Token invalid or expired
|
||||
auth.logout();
|
||||
goto('/login');
|
||||
}
|
||||
const user = await api.fetchApi('/auth/me');
|
||||
auth.setUser(user);
|
||||
} catch (e) {
|
||||
console.error('Failed to verify session:', e);
|
||||
auth.logout();
|
||||
|
||||
Reference in New Issue
Block a user