Path: blob/master/src/packages/next/pages/api/v2/auth/redeem-password-reset.ts
1454 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Redeeming a password reset works as follows:781. check that the password reset id is valid still; error if not92. check that the password is valid; error if not103. invalidate password reset id by writing that it is used to the database114. write hash of new password to the database125. respond success and sign user in.13*/1415import redeemPasswordReset from "@cocalc/server/auth/redeem-password-reset";16import { signUserIn } from "./sign-in";17import getParams from "lib/api/get-params";1819export default async function redeemPasswordResetAPIEndPoint(req, res) {20const { password, passwordResetId } = getParams(req);21let account_id: string;22try {23account_id = await redeemPasswordReset(password, passwordResetId);24} catch (err) {25res.json({ error: `${err.message}` });26return;27}28await signUserIn(req, res, account_id);29return;30}313233