mirror of
https://github.com/svemagie/indiekit-endpoint-microsub.git
synced 2026-04-02 15:35:00 +02:00
Restores complete implementation from feat/endpoint-microsub branch: - Reader UI with views (reader.njk, channel.njk, feeds.njk, etc.) - Feed polling, parsing, and normalization - WebSub subscriber - SSE realtime updates - Redis caching - Search indexing - Media proxy - Webmention processing
37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
/**
|
|
* Authentication utilities for Microsub
|
|
* @module utils/auth
|
|
*/
|
|
|
|
/**
|
|
* Get the user ID from request context
|
|
*
|
|
* In Indiekit, the userId can come from:
|
|
* 1. request.session.userId (if explicitly set)
|
|
* 2. request.session.me (from token introspection)
|
|
* 3. application.publication.me (single-user fallback)
|
|
* @param {object} request - Express request
|
|
* @returns {string|undefined} User ID
|
|
*/
|
|
export function getUserId(request) {
|
|
// Check session for explicit userId
|
|
if (request.session?.userId) {
|
|
return request.session.userId;
|
|
}
|
|
|
|
// Check session for me URL from token introspection
|
|
if (request.session?.me) {
|
|
return request.session.me;
|
|
}
|
|
|
|
// Fall back to publication me URL (single-user mode)
|
|
const { application } = request.app.locals;
|
|
if (application?.publication?.me) {
|
|
return application.publication.me;
|
|
}
|
|
|
|
// Final fallback: use "default" as user ID for single-user instances
|
|
// This ensures read state is tracked even without explicit user identity
|
|
return "default";
|
|
}
|