fix: Use api.js in AuthContext for session persistence
All checks were successful
Deploy Development / deploy (push) Successful in 43s
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:
parent
356ab18ec0
commit
edb33b8fc3
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user