@auth/core
@auth/core
is under active development.
This is the main entry point to the Auth.js library.
Based on the Request and Response Web standard APIs. Primarily used to implement framework-specific packages, but it can also be used directly.
Installationβ
- npm
- Yarn
- pnpm
npm install @auth/core
yarn add @auth/core
pnpm add @auth/core
Usageβ
import { Auth } from "@auth/core"
const request = new Request("https://example.com")
const response = await Auth(request, {...})
console.log(response instanceof Response) // true
Resourcesβ
Auth()β
Auth(request, config)β
Auth(
request
,config
):Promise
<ResponseInternal
>
Core functionality provided by Auth.js.
Receives a standard [Request]([object Object]) and returns a [Response]([object Object]).
Parametersβ
βͺ request: Request
βͺ config: AuthConfig
Returnsβ
Promise
< ResponseInternal
>
Exampleβ
import Auth from "@auth/core"
const request = new Request("https://example.com")
const response = await AuthHandler(request, {
providers: [...],
secret: "...",
trustHost: true,
})
Seeβ
Auth(request, config)β
Auth(
request
,config
):Promise
<Response
>
Core functionality provided by Auth.js.
Receives a standard [Request]([object Object]) and returns a [Response]([object Object]).
Parametersβ
βͺ request: Request
βͺ config: Omit
< AuthConfig
, "raw"
>
Returnsβ
Promise
< Response
>
Exampleβ
import Auth from "@auth/core"
const request = new Request("https://example.com")
const response = await AuthHandler(request, {
providers: [...],
secret: "...",
trustHost: true,
})
Seeβ
AuthConfigβ
Configure the Auth method.
Exampleβ
import Auth, { type AuthConfig } from "@auth/core"
export const authConfig: AuthConfig = {...}
const request = new Request("https://example.com")
const response = await AuthHandler(request, authConfig)
Seeβ
Propertiesβ
providersβ
providers:
Provider
[]
List of authentication providers for signing in (e.g. Google, Facebook, Twitter, GitHub, Email, etc) in any order. This can be one of the built-in providers or an object with a custom provider.
Defaultβ
[]
adapterβ
adapter?:
Adapter
You can use the adapter option to pass in your database adapter.
callbacksβ
callbacks?:
Partial
<CallbacksOptions
<Profile
,Account
> >
Callbacks are asynchronous functions you can use to control what happens when an action is performed. Callbacks are extremely powerful, especially in scenarios involving JSON Web Tokens as they allow you to implement access controls without a database and to integrate with external databases or APIs.
cookiesβ
cookies?:
Partial
<CookiesOptions
>
You can override the default cookie names and options for any of the cookies used by Auth.js. You can specify one or more cookies with custom properties and missing options will use the default values defined by Auth.js. If you use this feature, you will likely want to create conditional behavior to support setting different cookies policies in development and production builds, as you will be opting out of the built-in dynamic policy.
- β This is an advanced option. Advanced options are passed the same way as basic options, but may have complex implications or side effects. You should try to avoid using advanced options unless you are very comfortable using them.
Defaultβ
{}
debugβ
debug?:
boolean
Set debug to true to enable debug messages for authentication and database operations.
- β If you added a custom AuthConfig.logger, this setting is ignored.
Defaultβ
false
eventsβ
events?:
Partial
<EventCallbacks
>
Events are asynchronous functions that do not return a response, they are useful for audit logging. You can specify a handler for any of these events below - e.g. for debugging or to create an audit log. The content of the message object varies depending on the flow (e.g. OAuth or Email authentication flow, JWT or database sessions, etc), but typically contains a user object and/or contents of the JSON Web Token and other information relevant to the event.
Defaultβ
{}