diff options
| author | Fuwn <[email protected]> | 2024-10-09 00:41:20 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-10-09 00:41:43 -0700 |
| commit | 998b63a35256ac985a5a2714dd1ca451af4dfd8a (patch) | |
| tree | 50796121a9d5ab0330fdc5d7e098bda2860d9726 /src/lib/Utility/oauth.ts | |
| parent | feat(graphql): add badgeCount field (diff) | |
| download | due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.tar.xz due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.zip | |
chore(prettier): use spaces instead of tabs
Diffstat (limited to 'src/lib/Utility/oauth.ts')
| -rw-r--r-- | src/lib/Utility/oauth.ts | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/lib/Utility/oauth.ts b/src/lib/Utility/oauth.ts index bc71db5e..78f52bfa 100644 --- a/src/lib/Utility/oauth.ts +++ b/src/lib/Utility/oauth.ts @@ -1,51 +1,51 @@ import { redirect, type Cookies } from '@sveltejs/kit'; export interface ClientOptions { - id: string; - secret: string; - redirectURI: string; + id: string; + secret: string; + redirectURI: string; } export interface CallbackOptions { - url: URL; - cookies: Cookies; - cookie: string; - authorise: string; - redirect?: string; - client: ClientOptions; - verifier?: string; + url: URL; + cookies: Cookies; + cookie: string; + authorise: string; + redirect?: string; + client: ClientOptions; + verifier?: string; } export const callback = async (options: CallbackOptions) => { - const { url, cookies, cookie, authorise, client } = options; - const formData = new FormData(); + const { url, cookies, cookie, authorise, client } = options; + const formData = new FormData(); - formData.append('grant_type', 'authorization_code'); - formData.append('client_id', client.id); - formData.append('client_secret', client.secret); - formData.append('redirect_uri', client.redirectURI); - formData.append('code', url.searchParams.get('code') || 'null'); + formData.append('grant_type', 'authorization_code'); + formData.append('client_id', client.id); + formData.append('client_secret', client.secret); + formData.append('redirect_uri', client.redirectURI); + formData.append('code', url.searchParams.get('code') || 'null'); - if (options.verifier) formData.append('code_verifier', options.verifier); + if (options.verifier) formData.append('code_verifier', options.verifier); - cookies.set( - cookie, - JSON.stringify( - await ( - await fetch(authorise, { - method: 'POST', - body: formData - }) - ).json() - ), - { - path: '/', - maxAge: 60 * 60 * 24 * 7, - httpOnly: false, - sameSite: 'lax', - secure: false - } - ); + cookies.set( + cookie, + JSON.stringify( + await ( + await fetch(authorise, { + method: 'POST', + body: formData + }) + ).json() + ), + { + path: '/', + maxAge: 60 * 60 * 24 * 7, + httpOnly: false, + sameSite: 'lax', + secure: false + } + ); - throw redirect(303, options.redirect ?? '/'); + throw redirect(303, options.redirect ?? '/'); }; |