"use strict";
/*
Sign out of the current session or all sessions.

This invalidates 1 or more remember me cookies for
the account that is making the API request.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const get_account_1 = __importDefault(require("lib/account/get-account"));
const remember_me_1 = require("@cocalc/server/auth/remember-me");
const remember_me_2 = require("@cocalc/server/auth/remember-me");
const get_params_1 = __importDefault(require("lib/api/get-params"));
async function handle(req, res) {
    try {
        await signOut(req);
        res.json({});
    }
    catch (err) {
        res.json({ error: err.message });
    }
}
exports.default = handle;
async function signOut(req) {
    const { all } = (0, get_params_1.default)(req);
    if (all) {
        // invalidate all remember me cookies for this account.
        const account_id = await (0, get_account_1.default)(req);
        if (!account_id)
            return; // not signed in
        await (0, remember_me_2.deleteAllRememberMe)(account_id);
    }
    else {
        const hash = (0, remember_me_1.getRememberMeHash)(req);
        if (!hash)
            return; // not signed in
        await (0, remember_me_2.deleteRememberMe)(hash);
    }
}
//# sourceMappingURL=sign-out.js.map