feat: add DEV_MODE configuration and implement dev-token endpoint for authentication

This commit is contained in:
2026-04-07 10:39:07 +08:00
parent d12c1223f9
commit d170ba3362
4 changed files with 36 additions and 6 deletions

View File

@@ -22,7 +22,15 @@ export function AuthProvider({ children }: { children: ReactNode }) {
useEffect(() => {
const initAuth = async () => {
try {
const storedToken = localStorage.getItem('token')
let storedToken = localStorage.getItem('token')
if (!storedToken && import.meta.env.DEV) {
const res = await fetch('/api/auth/dev-token')
if (res.ok) {
const data = await res.json()
storedToken = data.access_token
localStorage.setItem('token', storedToken!)
}
}
if (storedToken) {
setToken(storedToken)
const currentUser = await authApi.getCurrentUser()