Auth.js (previously NextAuth.js) is a authentication library that is framework and runtime agnostic.

Check the Auth.js documentation for SvelteKit for more information.

Note that Auth.js and its adapter and framework API’s are pre-1.0. They are likely to change.

Setting up the Auth.js boilerplate

By default Launch Leopard uses the email provider (with magic login links) for authentication.

Here is how to set it up:

1

Create new Postgres db

Create a new Postgres database locally or on a db host like Railway or Vercel.

Postgres database docs (use to setup locally)

2

Update .env file

Update the .env file with your Postgres database connection string: PRIVATE_DATABASE_URL=[YOUR POSTGRES CONNECTION STRING]

3

Run migrations

The database schema has all the tables needed for Auth.js, located in src/lib/server/database/schema.ts

In your terminal, run

npm run db:generate
npm run db:migrate

to create the database migration files and run the migration with Drizzle Kit

4

Setup Loops

Make sure you have setup Loops (transcactional + marketing email platform), check the guide here.

You can also setup other methods to send emails, like using Nodemailer or Resend (these email services are transactional email only). You’ll have to change the sendVerificationRequest function in hooks.server.ts for this.
5

Create new Transactional email

Create a new transcactional email in Loops here.

Add a datavariable called verificationUrl in the email template. That’s where the verification url will be added.

You can customize and style the email template however you like.

Hit “Next” and publish the email template.

6

Set the transactional id

You should now see a TRANSACTIONAL ID.

Copy the TRANSACTIONAL ID and set it in hooks.server.ts in the EmailProvder provider in the body of the fetch request.

hooks.server.ts (Auth.js boilerplate)
export const handle = sequence(
  SvelteKitAuth({
    // ...
    providers: [
      EmailProvider({
        sendVerificationRequest: async ({ identifier: email, url }) => {
          await loops.sendTransactionalEmail("[YOUR TRANSACTIONAL ID]", email, {
            verificationUrl: url,
          });
        },
      }),
    ],
  })
  // ...
) satisfies Handle;

Other auth providers

Auth.js implements many auth providers, like email, Google, Facebook, Twitter, GitHub, and more.

Add the providers to your hooks.server.ts and signin pages.

See the Auth.js docs for more information how to implement other providers.

Database Adapters

Auth.js also implements many database adapters, like Drizzle, Supabase, Prisma, and more.

By default, Launch Leopard implements the Drizzle adapter.

See the database section for more information.