@rakered/nextjs-auth-api

api sdk for using @rakered/accounts with nextjs.

Usage no npm install needed!

<script type="module">
  import rakeredNextjsAuthApi from 'https://cdn.skypack.dev/@rakered/nextjs-auth-api';
</script>

README

@rakered/nextjs-auth-api

Next.js SDK for using user authentication persisted in MongoDB

social image

Usage

Create a Dynamic API Route handler at /pages/api/auth/[...slug].js

import { handleAuth } from '@rakered/nextjs-auth-api';

export default handleAuth();

Getting Started

Environment Variables

The library needs the following required configuration keys. These can be configured in a .env.local file in the root of your application (See more info about loading environmental variables in Next.js):

  • MAIL_URL String

    The smtp url for the mail server to use.

    Optional when running in development mode

  • JWT_SECRET String

    The secret to sign the jwt tokens with.

  • EMAIL_FROM String

    The email address that's being used as sender.

    Optional if options.email.from is provided

  • BASE_URL String

    The url that will be prefixed to magic urls and provided to the email template.

    Optional if options.email.siteUrl is provided

  • SITE_NAME String

    The site name that will be provided to the email template.

    Optional if options.email.siteName is provided

  • LOGO_URL String

    The url for the logo that will be shown in the email.

    Optional if options.email.logoUrl is provided

API Route

Create a Dynamic API Route handler at /pages/api/auth/[...slug].js

import { handleAuth } from '@rakered/nextjs-auth-api';

export default handleAuth();

This will create the following urls:

/api/auth/create-account
/api/auth/enroll-account
/api/auth/login
/api/auth/logout
/api/auth/refresh-token
/api/auth/reset-password
/api/auth/verify-email