@hellocoop/nextjs
Version:
Next.js SDK for Hellō https://hello.dev
29 lines (28 loc) • 1.24 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.auth = void 0;
const definitions_1 = require("@hellocoop/definitions");
const api_1 = require("@hellocoop/api");
const headers_1 = require("next/headers");
const helper_server_1 = require("@hellocoop/helper-server");
// set name and version to provide in metadata
const package_json_1 = __importDefault(require("../package.json"));
const { name, version } = package_json_1.default;
api_1.PackageMetadata.setMetadata(name, version);
// TODO cache decryption
// import { unstable_cache } from 'next/cache';
// https://nextjs.org/docs/app/api-reference/functions/unstable_cache
const auth = async function () {
var _a;
const authCookie = (_a = (0, headers_1.cookies)().get(api_1.configuration.cookies.authName)) === null || _a === void 0 ? void 0 : _a.value;
if (!authCookie)
return definitions_1.NotLoggedIn;
const a = await (0, helper_server_1.decryptObj)(authCookie, api_1.configuration.secret);
if (!a)
return definitions_1.NotLoggedIn;
return a;
};
exports.auth = auth;
;