Skip to content

TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.

745 B
Raw Blame
import type { NextFunction, Request, Response } from 'express';
import AuthController from '../AuthController';

export const IsLoggedIn = async (req: Request, res: Response, next: NextFunction) => {
    if (req.appUser.isApiTokenAuth() && !req.appUser.isBlocked()) {
        return next();
    }

    const token = req.headers['authorization']?.split(' ')[1];
    if (token) {
        const userPayload = await AuthController.validateTokens({ token, type: 'access' });
        if (
            userPayload
            && req.appUser.getTokenId() === userPayload.id
            && req.appUser.getHasActiveToken()
            && !req.appUser.isBlocked()
        ) {
            return next();
        }
    }
    return res.status(401).end();
};