work-in-progress atproto PDS
typescript atproto pds atcute
4
fork

Configure Feed

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

feat: pass IP over to sessions

Mary 4e59c183 d50f185d

+36 -3
+2 -2
packages/danaus/src/accounts/manager.ts
··· 1874 1874 interface CreateWebSessionOptions { 1875 1875 did: Did; 1876 1876 remember: boolean; 1877 - userAgent?: string; 1878 - ip?: string; 1877 + userAgent: string | undefined; 1878 + ip: string | undefined; 1879 1879 } 1880 1880 1881 1881 interface CreateLegacySessionOptions {
+2 -1
packages/danaus/src/pds-server.ts
··· 13 13 import type { AppConfig } from './config.ts'; 14 14 import { createAppContext, type AppContext } from './context.ts'; 15 15 import { createWebRouter } from './web/router.ts'; 16 + import { runWithServer } from './web/server-context.ts'; 16 17 17 18 export interface PdsServerOptions { 18 19 config: AppConfig; ··· 124 125 '/assets/webauthn-register.js': new Response(Bun.file(webauthnRegisterScript)), 125 126 '/assets/webauthn-authenticate.js': new Response(Bun.file(webauthnAuthenticateScript)), 126 127 127 - '/*': (request) => web.fetch(request), 128 + '/*': (request, server) => runWithServer(server, () => web.fetch(request)), 128 129 }, 129 130 }); 130 131 disposables.defer(() => server.stop());
+4
packages/danaus/src/web/controllers/login/lib/forms.ts
··· 13 13 14 14 import { getAppContext } from '#web/middlewares/app-context.ts'; 15 15 import { routes } from '#web/routes.ts'; 16 + import { getServer } from '#web/server-context.ts'; 16 17 17 18 export type AuthFactor = 'totp' | 'recovery' | 'password' | 'webauthn'; 18 19 ··· 139 140 did: account.did, 140 141 remember: data.remember ?? false, 141 142 userAgent: request.headers.get('user-agent') ?? undefined, 143 + ip: getServer().requestIP(request)?.address, 142 144 }); 143 145 144 146 setWebSessionToken(request, token, { ··· 203 205 did: challenge.did, 204 206 remember: challenge.remember, 205 207 userAgent: request.headers.get('user-agent') ?? undefined, 208 + ip: getServer().requestIP(request)?.address, 206 209 }); 207 210 208 211 setWebSessionToken(request, token, { ··· 306 309 did: challenge.did, 307 310 remember: challenge.remember, 308 311 userAgent: request.headers.get('user-agent') ?? undefined, 312 + ip: getServer().requestIP(request)?.address, 309 313 }); 310 314 311 315 setWebSessionToken(request, token, {
+28
packages/danaus/src/web/server-context.ts
··· 1 + import { AsyncLocalStorage } from 'node:async_hooks'; 2 + 3 + type BunServer = ReturnType<typeof Bun.serve>; 4 + 5 + const serverStorage = new AsyncLocalStorage<BunServer>(); 6 + 7 + /** 8 + * runs a callback with the server available via AsyncLocalStorage. 9 + * @param server bun server instance 10 + * @param fn callback to run 11 + * @returns result of the callback 12 + */ 13 + export const runWithServer = <T>(server: BunServer, fn: () => T): T => { 14 + return serverStorage.run(server, fn); 15 + }; 16 + 17 + /** 18 + * retrieves the bun server from the current async context. 19 + * @returns the bun server instance 20 + * @throws if called outside of a request context 21 + */ 22 + export const getServer = (): BunServer => { 23 + const server = serverStorage.getStore(); 24 + if (server === undefined) { 25 + throw new Error('server not available in current context'); 26 + } 27 + return server; 28 + };