Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/api/v2/accounts/sign-out.ts
Views: 687
/*1Sign out of the current session or all sessions.23This invalidates 1 or more remember me cookies for4the account that is making the API request.5*/67import getAccountId from "lib/account/get-account";8import { getRememberMeHash } from "@cocalc/server/auth/remember-me";9import {10deleteRememberMe,11deleteAllRememberMe,12} from "@cocalc/server/auth/remember-me";13import getParams from "lib/api/get-params";1415import { apiRoute, apiRouteOperation } from "lib/api";16import { SuccessStatus } from "lib/api/status";17import {18AccountSignOutInputSchema,19AccountSignOutOutputSchema,20} from "lib/api/schema/accounts/sign-out";2122async function handle(req, res) {23try {24await signOut(req);25res.json(SuccessStatus);26} catch (err) {27res.json({ error: err.message });28}29}3031async function signOut(req): Promise<void> {32const { all } = getParams(req);33if (all) {34// invalidate all remember me cookies for this account.35const account_id = await getAccountId(req);36if (!account_id) return; // not signed in37await deleteAllRememberMe(account_id);38} else {39const hash = getRememberMeHash(req);40if (!hash) return; // not signed in41await deleteRememberMe(hash);42}43}4445export default apiRoute({46signOut: apiRouteOperation({47method: "POST",48openApiOperation: {49tags: ["Accounts"],50},51})52.input({53contentType: "application/json",54body: AccountSignOutInputSchema,55})56.outputs([57{58status: 200,59contentType: "application/json",60body: AccountSignOutOutputSchema,61},62])63.handler(handle),64});656667