DebianArch64 / Scarlet

3rd party AppStore stuff
142 stars 23 forks source link

User #60

Closed tsukiytgames closed 4 months ago

tsukiytgames commented 4 months ago

import { FastifyPluginCallback, FastifyRequest } from 'fastify';

import rateLimit from 'express-rate-limit'; // @ts-expect-error - no types import MongoStoreRL from 'rate-limit-mongo';

import { AUTH0_DOMAIN, MONGOHQ_URL } from '../utils/env'; import { findOrCreateUser } from './helpers/auth-helpers';

declare module 'fastify' { interface Session { user: { id: string; }; } }

const getEmailFromAuth0 = async (req: FastifyRequest) => { const auth0Res = await fetch(https://${AUTH0_DOMAIN}/userinfo, { headers: { Authorization: req.headers.authorization ?? '' } });

if (!auth0Res.ok) { req.log.error(auth0Res); throw new Error('Invalid Auth0 Access Token'); }

const { email } = (await auth0Res.json()) as { email: string }; return email; };

/**