fix: Use api.js in AuthContext for session persistence
All checks were successful
Deploy Development / deploy (push) Successful in 43s

- AuthContext was using fetch() directly with relative URLs
- Relative URLs went to nginx port (3098) instead of backend (8098)
- Now uses api.getCurrentProfile() which has correct API_URL
- Session persistence should work after browser refresh
This commit is contained in:
Lars 2026-04-22 15:56:20 +02:00
parent 356ab18ec0
commit edb33b8fc3

View File

@ -1,4 +1,5 @@
import { createContext, useContext, useState, useEffect } from 'react'
import api from '../utils/api'
const AuthContext = createContext(null)
@ -18,19 +19,8 @@ export function AuthProvider({ children }) {
}
try {
const response = await fetch('/api/profiles/me', {
headers: {
'X-Auth-Token': token
}
})
if (response.ok) {
const profile = await response.json()
setUser(profile)
} else {
// Token invalid
localStorage.removeItem('authToken')
}
const profile = await api.getCurrentProfile()
setUser(profile)
} catch (err) {
console.error('Auth check failed:', err)
localStorage.removeItem('authToken')