Auth.js

website·Indexed 40 days ago

https://authjs.dev/

An open-source authentication solution providing a core set of providers and adapters for frameworks including Next.js (next-auth), Express, SvelteKit, and Qwik. It features a wide array of OAuth providers such as Spotify, Reddit, and Twitter/X, as well as database adapters for TypeORM, Hasura, SurrealDB, and Drizzle.

Tokens
137.5K
Snippets
911
Records
1.1K
Agent score
73%

What's inside Auth.js

  1. Overview of Auth.js Adapters

    Adapters allow Auth.js to integrate with any data layer (database, ORM, or backend API) to automatically manage users, handle account linking, support passwordless login, and store session information. While Auth.js defaults to a JWT-based session strategy (strategy: "jwt"), a database adapter can be used to persist sessions in a database. Before creating a custom adapter, check the official database adapters list to see if a compatible one already exists.
  2. Overview of Forward Email Provider

    The Forward Email provider enables passwordless sign-in using "magic links." When a user provides their email, a verification token is sent via email. Clicking this link verifies the user's identity and either creates a new account or signs them into an existing one. By default, verification tokens are valid for 24 hours.

    Critical Requirement: You must configure a database adapter to use this provider, as it requires a database to store verification tokens. It can be used alone or alongside OAuth providers.

  3. Overview of Postmark passwordless authentication

    The Postmark provider enables email-based sign-in using 'magic links'. When a user enters their email, a verification token is sent via email. Clicking this link verifies the user's identity and signs them in. If the user is new, an account is created upon first verification; otherwise, they are signed into their existing account. By default, verification tokens are valid for 24 hours.

    Critical Requirement: A database adapter must be configured to store verification tokens; email sign-in cannot function without a database.

  4. Overview of Loops magic link authentication

    The Loops provider enables email-based sign-in using 'magic links'. When a user signs in, a verification token (valid for 24 hours by default) is sent to their email. Clicking the link creates an account for new users or signs in existing users associated with that email address. This can be used alongside or instead of OAuth providers. Note that a database adapter is mandatory for the Loops provider to function; it cannot be used without a database.
  5. Overview of Auth.js Framework and Database Integrations

    Auth.js provides a set of framework-specific libraries and database adapters based on the @auth/core library. While most users interact with the framework-specific packages, the core library is intended for library authors.

    Framework Support Status:

    • NextAuth.js (next-auth): v5 (beta) and v4 (maintenance mode).
    • Qwik Auth (@auth/qwik): Released.
    • Express Auth (@auth/express): Experimental Release.
    • SvelteKit Auth (@auth/sveltekit): Experimental Release.
    • SolidStart Auth (@auth/solid-start): Experimental Release.
    • Astro, Fastify, Nuxt, and Remix: Currently in Open PR status.

    Database Adapter Support:

    • Use @auth/ ext{-adapter} packages for current development. These are fully compatible with next-auth and all @auth/* libraries.
    • @next-auth/ ext{-adapter} packages are no longer maintained; users should migrate to the @auth/* equivalents.
  6. Overview of Mailgun Email Sign-in

    The Mailgun provider enables 'magic link' authentication. When a user signs in with their email, a verification token is sent via email. If the user clicks the link within the validity period (default 24 hours), an account is created (if it doesn't exist) and the user is signed in. This provider can be used alongside or instead of OAuth providers.

    Critical Requirement: You must configure a database adapter to use the Mailgun provider; it is not possible to enable email sign-in without a database to store verification tokens.

  7. Overview of Nodemailer Provider

    The Nodemailer provider enables passwordless sign-in via "magic links". When a user provides their email, a verification token is sent to that address. If the user clicks the link within the validity period (default 24 hours), an account is created (if it doesn't exist) and the user is signed in.

    Critical Requirement: You must configure a database adapter to use the Nodemailer provider, as it requires a database to store verification tokens. It can be used alone or alongside OAuth providers.

  8. Overview of Auth.js

    Auth.js is a runtime-agnostic authentication library built on standard Web APIs. It is designed to integrate with modern JavaScript frameworks to provide a secure, private, and extensible authentication experience. This version of the documentation applies to next-auth@5.0.0-beta and later, as well as all other frameworks under the @auth/* namespace.
  9. Overview of OAuth providers in Auth.js

    Auth.js provides over 80 preconfigured OAuth providers to simplify the integration of third-party authentication. Popular supported providers include Google, GitHub, Twitter, Keycloak, and Okta.
  10. Overview of Auth.js JWT encryption

    The @auth/core/jwt module provides functions and types to encode and decode JWTs issued by Auth.js. By default, Auth.js JWTs are encrypted using the A256CBC-HS512 algorithm (JWE). The encryption key is derived from the AUTH_SECRET environment variable or a provided secret property. These JWTs are intended for use by the same application that issued them; for third-party API authentication, the Identity Provider should be used instead.
  11. Account entity schema for MikroORM adapter

    The Account entity stores information about the authentication provider used by a user. It implements RemoveIndex<AdapterAccount>.
    new Account(): Account
    
    // Properties
    access_token?: string;
    expires_at?: number; // Absolute timestamp in seconds
    id: string;
    id_token?: string;
    provider: string; // e.g., "google"
    providerAccountId: string; // OAuth id, email, or credentials id
    refresh_token?: string;
    scope?: string;
    session_state?: JsonValue;
    token_type?: Lowercase<string>;
    type: AdapterAccountType;
    user: User;
    userId: string;
  12. Understand the relationship between Auth.js and NextAuth.js

    Auth.js is the framework-independent core library that serves as the base for all Auth.js integrations. NextAuth.js is specifically the Next.js integration of this core library. While most official integrations are distributed under the @auth scope, NextAuth.js remains under the next-auth scope to minimize migration overhead. Other integrations are typically named by their framework (e.g., "SvelteKit Auth" or "Express Auth").