[READ-ONLY] Mirror of https://github.com/flo-bit/skywatched. review movies and tv shows, based on at proto skywatched.app
0

Configure Feed

Select the types of activity you want to include in your feed.

skywatched / src / routes / oauth / callback / +server.ts
1.4 kB 45 lines
1import { atclient } from '$lib/server/client'; 2import { error, redirect } from '@sveltejs/kit'; 3import type { RequestEvent } from '../../$types'; 4import { env } from '$env/dynamic/private'; 5import { encryptString } from '$lib/server/crypts'; 6import { decodeBase64, encodeBase64urlNoPadding } from '@oslojs/encoding'; 7import { Agent } from '@atproto/api'; 8import type { OAuthSession } from '@atproto/oauth-client-node'; 9 10export async function GET({ request, cookies }: RequestEvent) { 11 const params = new URLSearchParams(request.url.split('?')[1]); 12 13 let mySession: OAuthSession; 14 try { 15 const { session } = await atclient.callback(params); 16 mySession = session; 17 const key = decodeBase64(env.NYX_PASSWORD || ''); 18 const encrypted = await encryptString(key, session.did); 19 const encoded = encodeBase64urlNoPadding(encrypted); 20 cookies.set('sid', encoded, { 21 path: '/', 22 maxAge: 60 * 60 * 24 * 30, 23 httpOnly: true, 24 sameSite: 'lax' 25 }); 26 } catch (err) { 27 console.error(err); 28 error(500, { message: (err as Error).message }); 29 } 30 31 try { 32 const agent = new Agent(mySession); 33 34 await agent.com.atproto.repo.getRecord({ 35 repo: mySession.did, 36 collection: 'app.skywatched.settings', 37 rkey: 'self' 38 }); 39 // eslint-disable-next-line @typescript-eslint/no-unused-vars 40 } catch (_e) { 41 redirect(301, '/settings?new'); 42 } 43 44 redirect(301, '/'); 45}