mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 02:40:39 +09:00
feat(auth): add get-session endpoint and harden session resolution
Add /api/auth/get-session for board actors to retrieve their session info. Wrap resolveSession in try/catch to prevent unhandled errors from crashing requests when auth headers are missing or malformed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
dff78a6df4
commit
90dfa2e9cd
2 changed files with 27 additions and 1 deletions
|
|
@ -66,6 +66,23 @@ export async function createApp(
|
|||
resolveSession: opts.resolveSession,
|
||||
}),
|
||||
);
|
||||
app.get("/api/auth/get-session", (req, res) => {
|
||||
if (req.actor.type !== "board" || !req.actor.userId) {
|
||||
res.status(401).json({ error: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
res.json({
|
||||
session: {
|
||||
id: `paperclip:${req.actor.source}:${req.actor.userId}`,
|
||||
userId: req.actor.userId,
|
||||
},
|
||||
user: {
|
||||
id: req.actor.userId,
|
||||
email: null,
|
||||
name: req.actor.source === "local_implicit" ? "Local Board" : null,
|
||||
},
|
||||
});
|
||||
});
|
||||
if (opts.betterAuthHandler) {
|
||||
app.all("/api/auth/*authPath", opts.betterAuthHandler);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue