atproto pastebin service: https://plonk.li

use secure: true in prod

Changed files
+14 -16
src
+14 -16
src/routes.ts
··· 6 6 import { isValidHandle, AtUri } from "@atproto/syntax"; 7 7 import { IncomingMessage, ServerResponse } from "node:http"; 8 8 import { Agent } from "@atproto/api"; 9 - import { getPds, DidResolver } from "@atproto/identity"; 10 9 import { TID } from "@atproto/common"; 11 - import { Agent } from "@atproto/api"; 12 10 import { newShortUrl } from "#/db"; 13 11 14 12 import * as Paste from "#/lexicons/types/li/plonk/paste"; 15 13 import * as Comment from "#/lexicons/types/li/plonk/comment"; 16 - import { ComAtprotoRepoNS } from "#/lexicons"; 17 14 18 15 type Session = { 19 16 did: string; 20 17 }; 21 18 19 + async function getSession(req: IncomingMessage, res: ServerResponse<IncomingMessage>) { 20 + return await getIronSession<Session>(req, res, { 21 + cookieName: "plonk-id", 22 + password: env.PLONK_COOKIE_SECRET, 23 + cookieOptions: { 24 + secure: env.PLONK_NODE_ENV === 'production', 25 + }, 26 + }) 27 + } 28 + 22 29 async function getSessionAgent( 23 30 req: IncomingMessage, 24 31 res: ServerResponse<IncomingMessage>, 25 32 ctx: Ctx, 26 33 ) { 27 - const session = await getIronSession<Session>(req, res, { 28 - cookieName: "plonk-id", 29 - password: env.PLONK_COOKIE_SECRET, 30 - }); 34 + const session = await getSession(req, res); 31 35 if (!session.did) return null; 32 36 try { 33 37 const oauthSession = await ctx.oauthClient.restore(session.did); ··· 57 61 const params = new URLSearchParams(req.originalUrl.split("?")[1]); 58 62 try { 59 63 const { session } = await ctx.oauthClient.callback(params); 60 - const clientSession = await getIronSession<Session>(req, res, { 61 - cookieName: "plonk-id", 62 - password: env.PLONK_COOKIE_SECRET, 63 - }); 64 + const clientSession = await getSession(req, res); 64 65 //assert(!clientSession.did, "session already exists"); 65 66 clientSession.did = session.did; 66 67 await clientSession.save(); ··· 97 98 }); 98 99 99 100 router.get("/logout", async (req, res) => { 100 - const session = await getIronSession<Session>(req, res, { 101 - cookieName: "plonk-id", 102 - password: env.PLONK_COOKIE_SECRET, 103 - }); 101 + const session = await getSession(req, res); 104 102 session.destroy(); 105 103 return res.redirect("/"); 106 104 }); ··· 137 135 .selectAll() 138 136 .where("authorDid", "=", authorDid) 139 137 .execute(); 140 - let didHandleMap = {}; 138 + let didHandleMap: Record<string, string> = {}; 141 139 didHandleMap[authorDid] = await ctx.resolver.resolveDidToHandle(authorDid); 142 140 const ownAgent = await getSessionAgent(req, res, ctx); 143 141 if (!ownAgent) {