FreeStack

Magic Link Auth

Passwordless email authentication with Supabase. Includes login/signup pages, session management, protected route middleware, and email templates.

Next.jsAuthBuilt with Cursor
1.8k
Stars
8.9k
Installs
2
Deps
2
Comments

Install / Copy

npx create-freestack-module magic-link-auth

Code Preview

index.tsx
import { createClient } from "@supabase/supabase-js";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export async function middleware(request: NextRequest) {
  const supabase = createClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
  );

  const { data: { session } } = await supabase.auth.getSession();

  if (!session && request.nextUrl.pathname.startsWith("/dashboard")) {
    return NextResponse.redirect(new URL("/login", request.url));
  }

  return NextResponse.next();
}

export async function sendMagicLink(email: string) {
  const { error } = await supabase.auth.signInWithOtp({ email });
  if (error) throw error;
}
SE
securityfirst3 days ago

Clean implementation. Added rate limiting on the OTP endpoint and it works well.

IN
indie-hacker1 week ago

Set this up for my SaaS in 30 minutes. No more password reset flows to maintain!