Fix PocketID login redirect
Build and push images / validate (push) Successful in 3s
Build and push images / build-backend (push) Successful in 6s
Build and push images / build-worker (push) Successful in 5s
Build and push images / build-frontend (push) Successful in 11s

This commit is contained in:
2026-06-06 19:56:18 +01:00
parent df6c993709
commit b5fd17a597
2 changed files with 13 additions and 15 deletions
-10
View File
@@ -25,16 +25,6 @@ export default function App() {
if (token) fetchUser() if (token) fetchUser()
}, [token]) }, [token])
useEffect(() => {
const params = new URLSearchParams(window.location.search)
const urlToken = params.get('token')
if (urlToken) {
localStorage.setItem('token', urlToken)
useAuthStore.setState({ token: urlToken })
window.history.replaceState({}, '', '/')
}
}, [])
return ( return (
<Routes> <Routes>
<Route path="/login" element={<LoginPage />} /> <Route path="/login" element={<LoginPage />} />
+12 -4
View File
@@ -1,11 +1,21 @@
import { create } from 'zustand' import { create } from 'zustand'
import api from '../utils/api' import api from '../utils/api'
// Read token from URL params synchronously at module load time,
// before any component renders. This handles PocketID OAuth callbacks.
const params = new URLSearchParams(window.location.search)
const urlToken = params.get('token')
if (urlToken) {
localStorage.setItem('token', urlToken)
window.history.replaceState({}, '', '/')
}
const initialToken = urlToken || localStorage.getItem('token')
export const useAuthStore = create((set) => ({ export const useAuthStore = create((set) => ({
token: localStorage.getItem('token'), token: initialToken,
user: null, user: null,
isLoading: false, isLoading: false,
login: async (username, password) => { login: async (username, password) => {
set({ isLoading: true }) set({ isLoading: true })
try { try {
@@ -23,12 +33,10 @@ export const useAuthStore = create((set) => ({
throw e throw e
} }
}, },
logout: () => { logout: () => {
localStorage.removeItem('token') localStorage.removeItem('token')
set({ token: null, user: null }) set({ token: null, user: null })
}, },
fetchUser: async () => { fetchUser: async () => {
try { try {
const { data } = await api.get('/auth/me') const { data } = await api.get('/auth/me')