import { Request as ExpressRequest, Response as ExpressResponse, json } from "express";
import { rpcClient } from "src/utils/rpc";

export interface AuthInfo {
    loggedIn: boolean;
    moderator: boolean;
}

type CheckResult = Promise<ExpressResponse<CheckResult>>;
export const get = async (req: ExpressRequest, res: ExpressResponse): CheckResult => {
    if (!req.session?.userId) {
        return res.json({
            loggedIn: false,
            moderator: false,
        });
    }
    const { authorised } = await rpcClient.userAuthorised({ userId: req.session.userId });
    return res.json({
        loggedIn: true,
        moderator: authorised,
    });
};
