A build your own ATProto adventure, OAuth already figured out for you.
demo.atpoke.xyz
1//Inter faces required by oquth-client-node for storing sessions and state
2
3import type {
4 NodeSavedSession,
5 NodeSavedSessionStore,
6 NodeSavedState,
7 NodeSavedStateStore
8} from '@atproto/oauth-client-node';
9import { Cache, SESSION_STORE, STATE_STORE } from '$lib/server/cache';
10import { db } from '$lib/server/db';
11
12export class StateStore implements NodeSavedStateStore{
13
14 cache: Cache;
15
16 constructor(database: typeof db) {
17 this.cache = new Cache(database, STATE_STORE);
18 }
19
20 async del(key: string) {
21 await this.cache.delete(key);
22 }
23
24 async get(key: string){
25 const value = await this.cache.get(key);
26 return value ? JSON.parse(value) as NodeSavedState : undefined;
27 }
28
29 async set(key: string, value: NodeSavedState) {
30 const json = JSON.stringify(value);
31 await this.cache.set(key, json);
32 }
33}
34
35export class SessionStore implements NodeSavedSessionStore{
36
37 cache: Cache;
38
39 constructor(database: typeof db) {
40 this.cache = new Cache(database, SESSION_STORE);
41 }
42
43 async del(key: string) {
44 await this.cache.delete(key);
45 }
46
47 async get(key: string){
48 const value = await this.cache.get(key);
49 return value ? JSON.parse(value) as NodeSavedSession : undefined;
50 }
51
52 async set(key: string, value: NodeSavedSession) {
53 const json = JSON.stringify(value);
54 await this.cache.set(key, json);
55 }
56}