Fix login redirect: load user before navigating to dashboard
This commit is contained in:
@@ -195,7 +195,7 @@ export const getSavedRecommendations = () =>
|
||||
api.get<RecommendationItem[]>('/recommendations/saved').then((r) => r.data)
|
||||
|
||||
export const toggleSaveRecommendation = (id: string) =>
|
||||
api.post<{ saved: boolean }>(`/recommendations/${id}/toggle-save`).then((r) => r.data)
|
||||
api.post<{ saved: boolean }>(`/recommendations/${id}/save`).then((r) => r.data)
|
||||
|
||||
export const dislikeRecommendation = (id: string) =>
|
||||
api.post<{ disliked: boolean }>(`/recommendations/${id}/dislike`).then((r) => r.data)
|
||||
|
||||
@@ -33,7 +33,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (token) {
|
||||
if (token && !user) {
|
||||
loadUser().finally(() => setLoading(false))
|
||||
} else {
|
||||
setLoading(false)
|
||||
@@ -43,6 +43,13 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const loginFn = async (newToken: string) => {
|
||||
localStorage.setItem('vynl_token', newToken)
|
||||
setTokenState(newToken)
|
||||
// Load user immediately so ProtectedRoute sees them before navigate
|
||||
try {
|
||||
const userData = await getMe()
|
||||
setUser(userData)
|
||||
} catch {
|
||||
// will retry via useEffect
|
||||
}
|
||||
}
|
||||
|
||||
const logout = () => {
|
||||
|
||||
Reference in New Issue
Block a user