feat(oauth): implement OAuth page rendering and enhance authentication flow

This commit is contained in:
Anish Sarkar 2026-06-24 18:37:04 +05:30
parent c4e35ac21c
commit eb76c02d43
5 changed files with 191 additions and 21 deletions

View file

@ -8,6 +8,15 @@ type SessionState =
| { status: "authenticated"; authenticated: true; accessExpiresAt: number | null }
| { status: "unauthenticated"; authenticated: false; accessExpiresAt: null };
async function getSessionHeaders(): Promise<HeadersInit> {
if (typeof window === "undefined" || !window.electronAPI?.getAccessToken) {
return {};
}
const token = await window.electronAPI.getAccessToken();
return token ? { Authorization: `Bearer ${token}` } : {};
}
export function useSession() {
const [state, setState] = useState<SessionState>({
status: "loading",
@ -19,6 +28,7 @@ export function useSession() {
try {
const response = await fetch(buildBackendUrl("/auth/session"), {
credentials: "include",
headers: await getSessionHeaders(),
});
if (!response.ok) {
setState({