型定義
このモジュールには、コアパッケージのパブリックな型とインターフェースが含まれています。
インストール
npm install @auth/core
@auth/core/types
からこのサブモジュールをインポートできます。
使用方法
TypeScriptを使用しない場合でも、VS CodeなどのIDEは型を認識し、より良い開発エクスペリエンスを提供します。入力中に、特定のオブジェクト/関数の形状に関する候補が表示され、ドキュメント、例、その他の貴重なリソースへのリンクが表示される場合があります。
Auth
関数、およびオプションでAuthConfig
インターフェースを使用する場合、内部のすべては既に型付けされていますので、このモジュールから型をインポートする必要はほとんどありません。
Auth
関数内では、このモジュールからの型を1つも使用する必要はありません。
例
import { Auth } from "@auth/core"
const request = new Request("https://example.com")
const response = await Auth(request, {
callbacks: {
jwt(): JWT { // <-- This is unnecessary!
return { foo: "bar" }
},
session(
{ session, token }: { session: Session; token: JWT } // <-- This is unnecessary!
) {
return session
},
}
})
リソース
AuthConfig
再エクスポート AuthConfig
アカウント
通常、使用されているプロバイダーに関する情報を含み、OAuthプロバイダーから返されるさまざまなトークンであるTokenSet
を拡張します。
継承
Partial
<TokenEndpointResponse
>
プロパティ
access_token?
optional readonly access_token: string;
継承元
Partial.access_token
authorization_details?
optional readonly authorization_details: AuthorizationDetails[];
継承元
Partial.authorization_details
expires_at?
optional expires_at: number;
TokenEndpointResponse.expires_inに基づいて計算された値です。
TokenEndpointResponse.access_tokenの有効期限(秒単位)を表す絶対的なタイムスタンプです。
この値は、TokenEndpointResponse.refresh_tokenと共にトークンローテーションを実装するために使用できます。
参照
- https://authjs.dokyumento.jp/guides/refresh-token-rotation#database-strategy
- https://www.rfc-editor.org/rfc/rfc6749#section-5.1
expires_in?
optional readonly expires_in: number;
継承元
Partial.expires_in
id_token?
optional readonly id_token: string;
継承元
Partial.id_token
provider
provider: string;
このアカウントのプロバイダーIDです。例:「google」。完全なリストはhttps://authjs.dokyumento.jp/reference/core/providersを参照してください。
providerAccountId
providerAccountId: string;
この値は、アカウント作成に使用されているプロバイダーの種類によって異なります。
- OAuth/OIDC:
profile()
コールバックから返されるOAuthアカウントのIDです。 - メール: ユーザーのメールアドレスです。
- 資格情報:
authorize()
コールバックから返されるid
です。
refresh_token?
optional readonly refresh_token: string;
継承元
Partial.refresh_token
scope?
optional readonly scope: string;
継承元
Partial.scope
token_type?
optional readonly token_type: Lowercase<string>;
注: 値は大文字と小文字を区別しないため、常に小文字で返されます。
継承元
Partial.token_type
type
type: ProviderType;
このアカウントのプロバイダの種類
userId?
optional userId: string;
このアカウントが属するユーザーのID
参照
https://authjs.dokyumento.jp/reference/core/adapters#adapteruser
Authenticator
WebAuthnオーセンティケータ。アカウントの認証を行うエンティティを表し、オーセンティケータの資格情報と関連情報を格納します。
参照
https://www.w3.org/TR/webauthn/#authenticator
拡張元
プロパティ
counter
counter: number;
オーセンティケータが使用された回数。
credentialBackedUp
credentialBackedUp: boolean;
クライアントオーセンティケータが資格情報をバックアップしたかどうか。
credentialDeviceType
credentialDeviceType: string;
オーセンティケータのデバイスの種類。
credentialID
credentialID: string;
Base64エンコードされた資格情報ID。
credentialPublicKey
credentialPublicKey: string;
Base64エンコードされた資格情報の公開鍵。
providerAccountId
providerAccountId: string;
オーセンティケータに接続されているプロバイダアカウントID。
transports?
optional transports: null | string;
連結されたトランスポートフラグ。
userId?
optional userId: string;
このオーセンティケータが属するユーザーのID。
CookieOption
プロパティ
name
name: string;
options
options: SerializeOptions;
CookiesOptions
プロパティ
callbackUrl
callbackUrl: Partial<CookieOption>;
csrfToken
csrfToken: Partial<CookieOption>;
nonce
nonce: Partial<CookieOption>;
pkceCodeVerifier
pkceCodeVerifier: Partial<CookieOption>;
sessionToken
sessionToken: Partial<CookieOption>;
state
state: Partial<CookieOption>;
webauthnChallenge
webauthnChallenge: Partial<CookieOption>;
DefaultSession
拡張元
プロパティ
expires
expires: string;
user?
optional user: User;
LoggerInstance
任意のメソッドをオーバーライドできます。残りのメソッドはデフォルトのロガーを使用します。
拡張元
プロパティ
debug()
debug: (message, metadata?) => void;
パラメータ
パラメータ | 型 |
---|---|
message | string |
metadata ? | unknown |
戻り値
void
error()
error: (error) => void;
パラメータ
パラメータ | 型 |
---|---|
エラー | Error |
戻り値
void
warn()
warn: (code) => void;
パラメータ
パラメータ | 型 |
---|---|
code | WarningCode |
戻り値
void
PagesOptions
プロパティ
error
error: string;
エラーページへのパス。
オプションの "error" クエリパラメータは、利用可能な値のいずれかに設定されます。
デフォルト
"/error"
newUser
newUser: string;
設定されている場合、新規ユーザーは初回サインイン時にここにリダイレクトされます。
signIn
signIn: string;
サインインページへのパス。
オプションの "error" クエリパラメータは、利用可能な値のいずれかに設定されます。
デフォルト
"/signin"
signOut
signOut: string;
verifyRequest
verifyRequest: string;
Profile
OAuthプロバイダから返されるユーザー情報。
参照
https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
Indexable
[claim
: string
]: unknown
プロパティ
address?
optional address: null | {
country: null | string;
formatted: null | string;
locality: null | string;
postal_code: null | string;
region: null | string;
street_address: null | string;
};
birthdate?
optional birthdate: null | string;
email?
optional email: null | string;
email_verified?
optional email_verified: null | boolean;
family_name?
optional family_name: null | string;
gender?
optional gender: null | string;
given_name?
optional given_name: null | string;
id?
optional id: null | string;
locale?
optional locale: null | string;
middle_name?
optional middle_name: null | string;
name?
optional name: null | string;
nickname?
optional nickname: null | string;
phone_number?
optional phone_number: null | string;
picture?
optional picture: any;
preferred_username?
optional preferred_username: null | string;
profile?
optional profile: null | string;
sub?
optional sub: null | string;
updated_at?
optional updated_at: null | string | number | Date;
website?
optional website: null | string;
zoneinfo?
optional zoneinfo: null | string;
PublicProvider
プロパティ
callbackUrl
callbackUrl: string;
id
id: string;
name
name: string;
signinUrl
signinUrl: string;
type
type: string;
ResponseInternal<Body>
型パラメータ
型パラメータ | 値 |
---|---|
Body extends string | Record <string , any > | any [] | null | any |
プロパティ
body?
optional body: Body;
cookies?
optional cookies: Cookie[];
headers?
optional headers: HeadersInit;
リダイレクト?
optional redirect: string;
ステータス?
optional status: number;
セッション
ログインユーザーのアクティブなセッション。
拡張
プロパティ
有効期限
expires: string;
継承元
ユーザー?
optional user: User;
継承元
テーマ
ビルトインページのテーマを変更します。
プロパティ
ブランドカラー?
optional brandColor: string;
ボタンテキスト?
optional buttonText: string;
カラースキーム?
optional colorScheme: "auto" | "dark" | "light";
ロゴ?
optional logo: string;
ユーザー
OAuthプロバイダのprofile
コールバックで返されるオブジェクトの形状。 jwt
およびsession
コールバック、またはデータベースを使用する場合のsession
コールバックの第2パラメータで使用できます。
拡張元
プロパティ
メールアドレス?
optional email: null | string;
ID?
optional id: string;
画像?
optional image: null | string;
名前?
optional name: null | string;
AuthAction
type AuthAction:
| "callback"
| "csrf"
| "error"
| "providers"
| "session"
| "signin"
| "signout"
| "verify-request"
| "webauthn-options";
Auth.jsでサポートされているアクション。各アクションはREST APIエンドポイントにマップされます。アクションによっては、サーバーの状態を変更するかどうかによって、GET
とPOST
の両方のバリアントがあります。
"callback"
:GET
: OAuthプロバイダからのコールバックを処理します。POST
: クレデンシャルプロバイダからのコールバックを処理します。
"csrf"
: クッキー(暗号化)に保存されている生のCSRFトークンを返します。ダブルサブミットクッキー手法を実装するCSRF保護に使用されます。
一部のフレームワークにはビルトインのCSRF保護があり、このアクションを無効にできます。この場合、対応するエンドポイントは404応答を返します。skipCSRFCheck
で詳細を参照してください。 ⚠ 何をしているのか理解していない限り、手動でCSRF保護を無効にすることはお勧めしません。
"error"
: ビルトインのエラーページをレンダリングします。"providers"
: 構成されたすべてのプロバイダのクライアントセーフなリストを返します。"session"
:GET
: ユーザーのセッションが存在する場合はそれを返し、存在しない場合はnull
を返します。POST
: ユーザーのセッションを更新し、更新されたセッションを返します。
"signin"
:GET
: ビルトインのサインインページをレンダリングします。POST
: サインインフローを開始します。
"signout"
:GET
: ビルトインのサインアウトページをレンダリングします。POST
: サインアウトフローを開始します。これにより、ユーザーのセッションが無効になります(クッキーの削除、およびデータベースにセッションがある場合はそれも削除されます)。
"verify-request"
: ビルトインの検証リクエストページをレンダリングします。"webauthn-options"
:GET
: WebAuthn認証および登録フローのオプションを返します。
Awaitable<T>
type Awaitable<T>: T | PromiseLike<T>;
型パラメータ
型パラメータ |
---|
T |
Awaited<T>
type Awaited<T>: T extends Promise<infer U> ? U : T;
型パラメータ
型パラメータ |
---|
T |
ErrorPageParam
type ErrorPageParam: "Configuration" | "AccessDenied" | "Verification";
TODO: これらがすべて使用されている/正しいかどうかを確認してください
SemverString
type SemverString: v${number} | v${number}.${number} | v${number}.${number}.${number};
SignInPageErrorParam
type SignInPageErrorParam:
| "Signin"
| "OAuthSignin"
| "OAuthCallbackError"
| "OAuthCreateAccount"
| "EmailCreateAccount"
| "Callback"
| "OAuthAccountNotLinked"
| "EmailSignin"
| "CredentialsSignin"
| "SessionRequired";
TODO: これらがすべて使用されている/正しいかどうかを確認してください
TokenSet
type TokenSet: Partial<TokenEndpointResponse> & {
expires_at: number;
};
OAuthプロバイダによって返される異なるトークン。それらのいくつかは大文字と小文字が異なりますが、同じ値を参照しています。
型宣言
expires_at?
optional expires_at: number;
access_token
の有効期限(秒単位)。この値はexpires_in
の値から計算されます。
参照
https://www.ietf.org/rfc/rfc6749.html#section-4.2.2
WebAuthnOptionsResponseBody
type WebAuthnOptionsResponseBody: {
action: WebAuthnAuthenticate;
options: PublicKeyCredentialRequestOptionsJSON;
} | {
action: WebAuthnRegister;
options: PublicKeyCredentialCreationOptionsJSON;
};