Skip to main content
Version: Next

Interface: Auth

Authentication configuration and lifecycle hooks.

See the Auth overview for the supported auth methods and how the User entity is connected to auth. If hooks are async, Wasp awaits them. All hooks receive prisma and req in their input. Hook return values are ignored except for AuthHooks.onBeforeOAuthRedirect, which can change the redirect URL.

Extends

  • AuthHooks

Properties

methods

methods: AuthMethods

Enabled authentication methods.


onAfterEmailVerified?

optional onAfterEmailVerified?: Reference<AnyFunction>

Called once, after the user verifies their email. Receives email and user.

Inherited from

AuthHooks.onAfterEmailVerified


onAfterLogin?

optional onAfterLogin?: Reference<AnyFunction>

Called after a successful login. Receives providerId, user, and, for social auth, oauth fields including tokens and the unique OAuth request ID.

Inherited from

AuthHooks.onAfterLogin


onAfterSignup?

optional onAfterSignup?: Reference<AnyFunction>

Called after the user is created. Receives providerId, the created user, and, for social auth, oauth fields including tokens and the unique OAuth request ID.

Inherited from

AuthHooks.onAfterSignup


onAuthFailedRedirectTo

onAuthFailedRedirectTo: string

Route that Wasp redirects unauthenticated users to when they try to access a page that has authRequired: true.


onAuthSucceededRedirectTo?

optional onAuthSucceededRedirectTo?: string

Route that Wasp redirects users to after a successful login or signup.

Only takes effect when using Wasp's built-in Auth UI.

Default

"/"

onBeforeLogin?

optional onBeforeLogin?: Reference<AnyFunction>

Called before the user is logged in. Receives providerId and user. Throw from this hook to reject a login based on custom criteria.

Inherited from

AuthHooks.onBeforeLogin


onBeforeOAuthRedirect?

optional onBeforeOAuthRedirect?: Reference<AnyFunction>

Called before redirecting the user to the OAuth provider. Receives the generated url and oauth.uniqueRequestId. Return { url } to override the redirect URL.

Inherited from

AuthHooks.onBeforeOAuthRedirect


onBeforeSignup?

optional onBeforeSignup?: Reference<AnyFunction>

Called before the user is created. Receives providerId plus the common hook input. Throw from this hook to reject a signup based on custom criteria.

Inherited from

AuthHooks.onBeforeSignup


userEntity

userEntity: string

Name of the Prisma model that represents the application user connected to your business logic.

The model must be defined in schema.prisma and have an @id field. The ID can use any Prisma-supported ID type.