Add Google Client ID fetching in auth context and create auth config API route
Build and Push Reader Image / docker (push) Successful in 38s

This commit is contained in:
2026-04-24 02:08:33 +07:00
parent 7c4404ded8
commit 223850922e
3 changed files with 50 additions and 2 deletions
+31 -2
View File
@@ -77,6 +77,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
export function useAuth() {
const [sessionUser, setSessionUser] = useState<any>(null)
const [isLoading, setIsLoading] = useState(true)
const [googleClientId, setGoogleClientId] = useState("")
const fetchSession = useCallback(async () => {
try {
@@ -100,6 +101,34 @@ export function useAuth() {
fetchSession()
}, [fetchSession])
useEffect(() => {
let active = true
const fetchAuthConfig = async () => {
try {
const res = await fetch("/api/auth/config", { cache: "no-store" })
if (!res.ok) {
return
}
const data = await res.json()
if (active) {
setGoogleClientId(String(data?.googleClientId || "").trim())
}
} catch {
if (active) {
setGoogleClientId("")
}
}
}
void fetchAuthConfig()
return () => {
active = false
}
}, [])
const user: User | null = useMemo(() => {
if (!sessionUser) return null
return {
@@ -114,9 +143,9 @@ export function useAuth() {
}, [sessionUser])
const loginWithGoogle = async () => {
const clientId = (process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID || "").trim()
const clientId = googleClientId.trim()
if (!clientId) {
throw new Error("NEXT_PUBLIC_GOOGLE_CLIENT_ID is not configured")
throw new Error("Google client id is not configured on server runtime")
}
const googleIdToken = await requestGoogleIdToken(clientId)