Skip to content

nuxflare/auth

Repository files navigation

Nuxflare Auth Login Screen

Nuxflare Auth

A modern, lightweight, self-hosted auth server built with Cloudflare, Nuxt, and OpenAuth.js.

What's This?

Nuxflare Auth lets you add authentication to your apps without the headache. It's a monorepo that bundles everything you need:

  • A slick auth UI built with Nuxt 3 and @nuxt/ui
  • Backend auth magic running on Cloudflare Workers
  • A ready-to-use example so you can see how it all fits together

Features

  • 🔒 Complete authentication UI including:
    • Code-based login
    • Password-based login
    • Forgot password flow
    • User registration
  • 🔑 OAuth2 authentication with GitHub and Google (easily add more providers)
  • ✉️ Emails using Resend (or use any other provider)
  • ⚡ Lightning-fast, powered by Cloudflare's edge network

Project Layout

packages/
  ├── auth-frontend/   # auth UI components
  ├── emails/          # react email templates
  ├── example-client/  # example nuxt client
  └── functions/       # cloudflare workers

Prerequisites

Before getting started, you'll need:

  • pnpm
  • A Cloudflare account
  • OAuth credentials from Google and GitHub
  • A Resend API key for sending emails

Getting Started

  1. Clone the repository and install dependencies:

    git clone https://github.com/nuxflare/auth nuxflare-auth
    cd nuxflare-auth
    pnpm install
  2. Create and Configure API Token:

    a. Create a Cloudflare API token with the required permissions using this link.
    b. Set the CLOUDFLARE_API_TOKEN environment variable:

    export CLOUDFLARE_API_TOKEN=GahXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  3. Configure your secrets:

    # OAuth stuff
    pnpm sst secret set GoogleClientID your_client_id
    pnpm sst secret set GoogleClientSecret your_client_secret
    pnpm sst secret set GithubClientID your_client_id
    pnpm sst secret set GithubClientSecret your_client_secret
    
    # For emails
    pnpm sst secret set ResendApiKey your_resend_api_key
  4. Configure your fromEmail in sst.config.ts:

    async run() {
      const fromEmail = "hi@nuxflare.com";
      // ...
    }
  5. Start local development:

    pnpm dev
  6. Deploy to production:

    pnpm sst deploy --stage production

Architecture

Frontend (packages/auth-frontend)

Login, signup, sign in with code, and forgot password flows built with Nuxt and Nuxt UI.

Backend (packages/functions)

The backend consists of two main components:

  • auth.ts: Core authentication logic handler
  • emails.tsx: Sending emails with Resend

Everything is stored in Cloudflare KV—sessions, users, etc. Plus, it all runs on the edge, so it's super fast.

Example Implementation

Check out packages/example-client to see how to add auth to your own app.

Support

Found a bug? Please open an issue on our GitHub repository.

About

A modern, lightweight, self-hosted auth server built with Cloudflare, Nuxt, and OpenAuth.js.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published