Skip to main content

react

Client-side methods for NextAuth.js.

SessionProvider()​

Provider to wrap the app in to make session data available globally. Can also be used to throttle the number of requests to the endpoint /api/auth/session.

SessionProvider(props: SessionProviderProps): Element

Parameters​

ParameterType
propsSessionProviderProps

Returns​

Element


signIn()​

Initiate a signin flow or send the user to the signin page listing all possible providers. Handles CSRF protection.

signIn<P>(provider?: LiteralUnion<P extends RedirectableProviderType ? BuiltInProviderType | P : BuiltInProviderType, string>, options?: SignInOptions, authorizationParams?: SignInAuthorizationParams): Promise<P extends RedirectableProviderType ? SignInResponse | undefined : undefined>

Type parameters​

  • P extends undefined | RedirectableProviderType = undefined

Parameters​

ParameterType
provider?LiteralUnion<P extends RedirectableProviderType ? BuiltInProviderType | P : BuiltInProviderType, string>
options?SignInOptions
authorizationParams?SignInAuthorizationParams

Returns​

Promise<P extends RedirectableProviderType ? SignInResponse | undefined : undefined>


signOut()​

Initiate a signout, by destroying the current session. Handles CSRF protection.

signOut<R>(options?: SignOutParams<R>): Promise<R extends true ? undefined : SignOutResponse>

Type parameters​

  • R extends boolean = true

Parameters​

ParameterType
options?SignOutParams<R>

Returns​

Promise<R extends true ? undefined : SignOutResponse>


useSession()​

React Hook that gives you access to the logged in user's session data.

useSession<R>(options?: UseSessionOptions<R>): SessionContextValue<R>

Type parameters​

  • R extends boolean

Parameters​

ParameterType
options?UseSessionOptions<R>

Returns​

SessionContextValue<R>


LiteralUnion​

LiteralUnion: <T, U> T | U & Record<never, never>

Util type that matches some strings literally, but allows any other string as well.

Source​

https://github.com/microsoft/TypeScript/issues/29729#issuecomment-832522611

Type parameters​

  • T extends U
  • U = string

SignInAuthorizationParams​

SignInAuthorizationParams: string | string[][] | Record<string, string> | URLSearchParams

Match inputType of new URLSearchParams(inputType)