mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-30 21:59:46 +02:00
feat(oauth): implement OAuth page rendering and enhance authentication flow
This commit is contained in:
parent
c4e35ac21c
commit
eb76c02d43
5 changed files with 191 additions and 21 deletions
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue