hensei-web/src/lib/auth/oauth.ts
Justin Edmund ebc0e48e92 fix: Phase 5 - fix environment variable imports (38 -> 37 errors)
Resolved PUBLIC_SIERO_OAUTH_URL import issue by removing the intermediate
config.ts file and importing environment variables directly where needed.

Changes:
- Removed src/lib/config.ts (unnecessary abstraction layer)
- Updated src/lib/auth/oauth.ts to import PUBLIC_SIERO_API_URL directly
- Updated src/routes/auth/refresh/+server.ts to import directly
- Construct OAUTH_BASE locally as `${PUBLIC_SIERO_API_URL}/oauth`

This fixes the TypeScript error where svelte-check couldn't resolve
PUBLIC_SIERO_OAUTH_URL from the config file, even though the variable
was properly defined in .env and .svelte-kit/ambient.d.ts.

Result: 38 → 37 errors (-1)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 19:33:15 -08:00

46 lines
1.1 KiB
TypeScript

import { PUBLIC_SIERO_API_URL } from '$env/static/public'
const OAUTH_BASE = `${PUBLIC_SIERO_API_URL}/oauth`
export interface OAuthLoginResponse {
access_token: string
token_type: 'Bearer'
expires_in: number
refresh_token: string
created_at: number
user: {
id: string
username: string
role: number
}
}
// Response from user info endpoint used during auth flow
export interface UserInfoResponse {
id: string
username: string
role: number
avatar: {
picture: string | null
element: string | null
}
language: string | null
gender: number | null
theme: string | null
}
export async function passwordGrantLogin(
fetchFn: typeof fetch,
body: { email: string; password: string; grant_type: 'password' }
): Promise<OAuthLoginResponse> {
const url = `${OAUTH_BASE}/token`
const res = await fetchFn(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
})
if (res.status === 401) throw new Error('unauthorized')
if (!res.ok) throw new Error(`oauth_error_${res.status}`)
return res.json() as Promise<OAuthLoginResponse>
}