UNPKG

@hellocoop/api

Version:

Client API for Hellō https://hello.dev

46 lines (45 loc) 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateAuth = exports.clearAuth = exports.handleAuth = void 0; const auth_1 = require("../lib/auth"); const handleAuth = async function (req, res) { res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate'); res.setHeader('Pragma', 'no-cache'); res.setHeader('Expires', '0'); res.json(await (0, auth_1.getAuthfromCookies)(req, res)); }; exports.handleAuth = handleAuth; const clearAuth = async function (res) { (0, auth_1.clearAuthCookie)(res); }; exports.clearAuth = clearAuth; const updateAuth = async function (req, res, authUpdates) { const auth = await (0, auth_1.getAuthfromCookies)(req, res); if (!auth.isLoggedIn) return auth; const newAuth = { ...auth, ...authUpdates, sub: auth.sub, iat: auth.iat }; const success = await (0, auth_1.saveAuthCookie)(res, newAuth); if (success) return newAuth; return null; }; exports.updateAuth = updateAuth; // export const handleCookieTokenVerify = async function ( req: HelloRequest, res: HelloResponse) { // const cookieToken = req.body // if (!cookieToken) // return res.status(400).send('Invalid request') // try { // const auth = await decryptObj( cookieToken, config.secret as string) as Auth | undefined // if (auth) { // return res.json(auth) // } // } catch( e ) { // console.error(e) // } // return res.status(401).send('Unauthorized') // }