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 { createContext, useContext, useState, useEffect } from 'react'
|
||||||
|
import api from '../utils/api'
|
||||||
|
|
||||||
const AuthContext = createContext(null)
|
const AuthContext = createContext(null)
|
||||||
|
|
||||||
|
|
@ -18,19 +19,8 @@ export function AuthProvider({ children }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/profiles/me', {
|
const profile = await api.getCurrentProfile()
|
||||||
headers: {
|
|
||||||
'X-Auth-Token': token
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
const profile = await response.json()
|
|
||||||
setUser(profile)
|
setUser(profile)
|
||||||
} else {
|
|
||||||
// Token invalid
|
|
||||||
localStorage.removeItem('authToken')
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Auth check failed:', err)
|
console.error('Auth check failed:', err)
|
||||||
localStorage.removeItem('authToken')
|
localStorage.removeItem('authToken')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user