16 lines
418 B
JavaScript
16 lines
418 B
JavaScript
/** @typedef {import('koa').Context} Context */
|
|
/** @typedef {import('koa').Next} Next */
|
|
|
|
/**
|
|
* Middleware function to check if user is logged in.
|
|
* @param {Context} ctx - Koa context object.
|
|
* @param {Next} next - Next middleware function.
|
|
*/
|
|
export function loginRequired(ctx, next) {
|
|
if (ctx.state.user == null) {
|
|
ctx.status = 401; // 401 (Unauthorized)
|
|
} else {
|
|
return next();
|
|
}
|
|
}
|