Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.0 kB ยท 67 lines
TypeScript
at incident-api
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import { db, eq } from "@openstatus/db";import { viewer } from "@openstatus/db/src/schema";import type { DefaultSession } from "next-auth";import NextAuth, { AuthError } from "next-auth";import { headers } from "next/headers";
import { getValidCustomDomain } from "../domain";import { getQueryClient, trpc } from "../trpc/server";import { adapter } from "./adapter";import { logger } from "./logger";import { ResendProvider } from "./providers";
export type { DefaultSession };
export const { handlers, signIn, signOut, auth } = NextAuth({ debug: process.env.NODE_ENV === "development", adapter, logger, providers: [ResendProvider], callbacks: { async signIn(params) { const _headers = await headers(); const host = _headers.get("host");
if (!host) throw new AuthError("No host found");
const protocol = _headers.get("x-forwarded-proto") || "https"; const req = new Request(`${protocol}://${host}`, { headers: new Headers(_headers), }); const { prefix } = getValidCustomDomain(req);
if (!prefix || !params.user.email) return false;
const queryClient = getQueryClient(); // NOTE: throws an error if the email domain is not allowed const query = await queryClient.fetchQuery( trpc.statusPage.validateEmailDomain.queryOptions({ slug: prefix, email: params.user.email, }), );
if (!query) return false;
if (params.account?.provider === "resend") { // if the user is new, the id is the verification_token and not the viewer id, so we cannot update the viewer if (Number.isNaN(Number(params.user.id))) return true; await db .update(viewer) .set({ updatedAt: new Date() }) .where(eq(viewer.id, Number(params.user.id))) .run();
return true; }
return false; }, redirect: async (params) => { return params.url; }, async session(params) { return params.session; }, },});