Skip to main content

Auth Providers

Auth providers handle user authentication and identity management. They support various authentication methods including email/password, OAuth providers (Google, GitHub), and custom authentication flows.

Available Auth Providers

Medusa includes three authentication providers:

Email/Password Provider

@medusajs/medusa/auth-emailpass - Traditional email and password authentication. Features:
  • User registration with email and password
  • Secure password hashing using Scrypt
  • Password updates
  • Email-based authentication

Google OAuth Provider

@medusajs/medusa/auth-google - Google OAuth 2.0 authentication. Features:
  • Google Sign-In integration
  • OAuth 2.0 flow
  • Email verification enforcement
  • User profile metadata (name, picture, etc.)

GitHub OAuth Provider

@medusajs/medusa/auth-github - GitHub OAuth authentication. Features:
  • GitHub Sign-In integration
  • OAuth flow
  • User profile metadata

Installation

All auth providers are included in the core Medusa package:

Configuration

Configure email/password authentication:
medusa-config.ts
Higher logN values increase security but slow down hashing. The default (15) provides a good balance for most applications.

Auth Provider Interface

All auth providers extend AbstractAuthModuleProvider and implement the following methods:

authenticate(input: AuthenticationInput, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>

Authenticates a user. Email/Password Example:
OAuth Example (Google/GitHub):

register(input: AuthenticationInput, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>

Registers a new user (email/password only).
OAuth providers (Google, GitHub) throw an error when register is called. Use authenticate for OAuth flows.

validateCallback(input: AuthenticationInput, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>

Validates OAuth callback (OAuth providers only).

update(data: any, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>

Updates auth identity (email/password only).

Using the Auth Module

Access auth providers through the Auth Module:

Authentication Flows

Email/Password Flow

  1. Registration:
  2. Login:
  3. Password Update:

OAuth Flow (Google/GitHub)

  1. Initiate OAuth:
  2. Handle Callback:
  3. Access User Data:

Creating Custom Auth Providers

Create a custom auth provider by extending AbstractAuthModuleProvider:
packages/modules/providers/auth-custom/src/services/custom-auth.ts
Register your custom provider:
packages/modules/providers/auth-custom/src/index.ts

Reference

  • Email/Password: packages/modules/providers/auth-emailpass/src/services/emailpass.ts
  • Google OAuth: packages/modules/providers/auth-google/src/services/google.ts
  • GitHub OAuth: packages/modules/providers/auth-github/src/services/github.ts
  • Base class: packages/core/utils/src/auth/abstract-auth-module-provider.ts
  • Types: packages/core/types/src/auth/provider.ts

Next Steps

Providers Overview

Explore other provider types

Notification Providers

Send welcome emails to new users