Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: magic link in dev mode (#806)
Maximilian Kaske2636e1c98996
diff --git a/apps/web/src/app/app/(auth)/login/_components/actions.ts b/apps/web/src/app/app/(auth)/login/_components/actions.tsnew file mode 100644index 000000000..6c6e1f9e7--- /dev/null+++ b/apps/web/src/app/app/(auth)/login/_components/actions.ts@@ -0,0 +1,11 @@+"use server";++import { signIn } from "@/lib/auth";++export async function signInWithResendAction(formData: FormData) {+ try {+ await signIn("resend", formData);+ } catch (e) {+ // console.error(e);+ }+}diff --git a/apps/web/src/app/app/(auth)/login/_components/magic-link-form.tsx b/apps/web/src/app/app/(auth)/login/_components/magic-link-form.tsxnew file mode 100644index 000000000..6090e4021--- /dev/null+++ b/apps/web/src/app/app/(auth)/login/_components/magic-link-form.tsx@@ -0,0 +1,38 @@+"use client";++import { useFormStatus } from "react-dom";++import { Button, Input, Label } from "@openstatus/ui";++import { LoadingAnimation } from "@/components/loading-animation";+import { toast, toastAction } from "@/lib/toast";+import { signInWithResendAction } from "./actions";++/**+ * @deprecated - only to be used in development mode+ */+export default function MagicLinkForm() {+ const { pending } = useFormStatus();++ return (+ <form+ action={async (formData) => {+ try {+ await signInWithResendAction(formData);+ toast.success("Check your terminal for the magic link.");+ } catch (e) {+ toastAction("error");+ }+ }}+ className="grid gap-2"+ >+ <div className="grid gap-1.5">+ <Label htmlFor="email">Email</Label>+ <Input id="email" name="email" type="email" required />+ </div>+ <Button variant="secondary" className="w-full">+ {pending ? <LoadingAnimation /> : "Console magic link"}+ </Button>+ </form>+ );+}diff --git a/apps/web/src/app/app/(auth)/login/page.tsx b/apps/web/src/app/app/(auth)/login/page.tsxindex 9a2ece15c..c5cdfc659 100644--- a/apps/web/src/app/app/(auth)/login/page.tsx+++ b/apps/web/src/app/app/(auth)/login/page.tsx@@ -1,11 +1,15 @@import Link from "next/link";import { z } from "zod";-import { Button } from "@openstatus/ui";+import { Button, Separator } from "@openstatus/ui";import { Shell } from "@/components/dashboard/shell";+import DevModeContainer from "@/components/dev-mode-container";import { Icons } from "@/components/icons";import { signIn } from "@/lib/auth";+import MagicLinkForm from "./_components/magic-link-form";++const isDev = process.env.NODE_ENV === "development";/*** allowed URL search params@@ -31,6 +35,12 @@ export default function Page({</p></div><div className="grid gap-3">+ {isDev ? (+ <DevModeContainer className="grid gap-3">+ <MagicLinkForm />+ <Separator />+ </DevModeContainer>+ ) : null}<formaction={async () => {"use server";diff --git a/apps/web/src/components/dev-mode-container.tsx b/apps/web/src/components/dev-mode-container.tsxnew file mode 100644index 000000000..494532b71--- /dev/null+++ b/apps/web/src/components/dev-mode-container.tsx@@ -0,0 +1,25 @@+import * as React from "react";++import { cn } from "@/lib/utils";++export default function DevModeContainer({+ children,+ className,+}: {+ children: React.ReactNode;+ className?: string;+}) {+ return (+ <div+ className={cn(+ "border-destructive/80 relative -m-2 rounded-lg border-2 p-2",+ className,+ )}+ >+ <p className="text-destructive bg-background absolute -top-2 left-3 px-1 text-xs font-medium uppercase">+ dev mode+ </p>+ {children}+ </div>+ );+}diff --git a/apps/web/src/components/layout/header/user-nav.tsx b/apps/web/src/components/layout/header/user-nav.tsxindex fb52a4de5..9991a2809 100644--- a/apps/web/src/components/layout/header/user-nav.tsx+++ b/apps/web/src/components/layout/header/user-nav.tsx@@ -37,7 +37,7 @@ export function UserNav() {`${session.data.user?.firstName} ${session.data.user?.lastName}`}/>- <AvatarFallback></AvatarFallback>+ <AvatarFallback className="from-foreground to-muted via-muted-foreground bg-gradient-to-br opacity-70" /></Avatar></Button></DropdownMenuTrigger>diff --git a/apps/web/src/lib/auth/adapter.ts b/apps/web/src/lib/auth/adapter.tsindex e9fa5b549..b95acd8fa 100644--- a/apps/web/src/lib/auth/adapter.ts+++ b/apps/web/src/lib/auth/adapter.ts@@ -10,7 +10,7 @@ import {verificationToken,} from "@openstatus/db/src/schema";-import { createUser, getUser } from "./helper";+import { createUser, getUser } from "./helpers";export type { DefaultSession };diff --git a/apps/web/src/lib/auth/helper.ts b/apps/web/src/lib/auth/helpers.tssimilarity index 100%rename from apps/web/src/lib/auth/helper.tsrename to apps/web/src/lib/auth/helpers.tsdiff --git a/apps/web/src/lib/auth/index.ts b/apps/web/src/lib/auth/index.tsindex 27547e9eb..fe77899fa 100644--- a/apps/web/src/lib/auth/index.ts+++ b/apps/web/src/lib/auth/index.ts@@ -1,36 +1,23 @@import type { DefaultSession } from "next-auth";import NextAuth from "next-auth";-import GitHub from "next-auth/providers/github";-import Google from "next-auth/providers/google";import { analytics, trackAnalytics } from "@openstatus/analytics";-// import Credentials from "next-auth/providers/credentials";-import { db, eq } from "@openstatus/db";import { user } from "@openstatus/db/src/schema";import { sendEmail, WelcomeEmail } from "@openstatus/emails";import { adapter } from "./adapter";+import { GitHubProvider, GoogleProvider, ResendProvider } from "./providers";export type { DefaultSession };export const { handlers, signIn, signOut, auth } = NextAuth({// debug: true,adapter,- providers: [- GitHub({ allowDangerousEmailAccountLinking: true }),- Google({- allowDangerousEmailAccountLinking: true,- authorization: {- params: {- // See https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest- prompt: "select_account",- // scope:- // "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",- },- },- }),- ],+ providers:+ process.env.NODE_ENV === "development"+ ? [GitHubProvider, GoogleProvider, ResendProvider]+ : [GitHubProvider, GoogleProvider],callbacks: {async signIn(params) {// We keep updating the user info when we loggin in@@ -39,8 +26,6 @@ export const { handlers, signIn, signOut, auth } = NextAuth({if (!params.profile) return true;if (Number.isNaN(Number(params.user.id))) return true;- console.log(params.profile);-await db.update(user).set({@@ -57,8 +42,6 @@ export const { handlers, signIn, signOut, auth } = NextAuth({if (!params.profile) return true;if (Number.isNaN(Number(params.user.id))) return true;- console.log(params.profile);-await db.update(user).set({diff --git a/apps/web/src/lib/auth/providers.ts b/apps/web/src/lib/auth/providers.tsnew file mode 100644index 000000000..c990eaf60--- /dev/null+++ b/apps/web/src/lib/auth/providers.ts@@ -0,0 +1,28 @@+import GitHub from "next-auth/providers/github";+import Google from "next-auth/providers/google";+import Resend from "next-auth/providers/resend";++export const GitHubProvider = GitHub({+ allowDangerousEmailAccountLinking: true,+});++export const GoogleProvider = Google({+ allowDangerousEmailAccountLinking: true,+ authorization: {+ params: {+ // See https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest+ prompt: "select_account",+ // scope:+ // "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",+ },+ },+});++export const ResendProvider = Resend({+ apiKey: undefined, // REMINDER: keep undefined to avoid sending emails+ async sendVerificationRequest(params) {+ console.log("");+ console.log(`>>> Magic Link: ${params.url}`);+ console.log("");+ },+});