@auth/qwik
AuthError
所有 Auth.js 错误的基类错误。它经过优化,可以通过 logger.error 选项以格式良好的方式在服务器日志中打印。
扩展
构造函数
new AuthError(message, errorOptions)
new AuthError(message?, errorOptions?): AuthError参数
| 参数 | 类型 |
|---|---|
message? | string | ErrorOptions |
errorOptions? | ErrorOptions |
返回值
重写
Error.constructor
属性
cause?
optional cause: Record<string, unknown> & {
err: Error;
};类型声明
err?
optional err: Error;重写
Error.cause
message
message: string;继承自
Error.message
name
name: string;继承自
Error.name
stack?
optional stack: string;继承自
Error.stack
type
type: ErrorType;错误类型。用于识别日志中的错误。
prepareStackTrace()?
static optional prepareStackTrace: (err, stackTraces) => any;格式化堆栈跟踪的可选重写
参见
https://v8.node.org.cn/docs/stack-trace-api#customizing-stack-traces
参数
| 参数 | 类型 |
|---|---|
err | Error |
stackTraces | CallSite[] |
返回值
any
继承自
Error.prepareStackTrace
stackTraceLimit
static stackTraceLimit: number;继承自
Error.stackTraceLimit
方法
captureStackTrace()
static captureStackTrace(targetObject, constructorOpt?): void在目标对象上创建 .stack 属性
参数
| 参数 | 类型 |
|---|---|
targetObject | object |
constructorOpt? | Function |
返回值
void
继承自
Error.captureStackTrace
CredentialsSignin
可以从 Credentials 提供商的 authorize 回调中抛出。当 authorize 回调期间发生错误时,可能会发生两件事
- 用户被重定向到登录页面,URL 中包含
error=CredentialsSignin&code=credentials。code是可配置的。 - 如果你在处理服务器端表单操作的框架中抛出此错误,则会抛出此错误,而不是重定向用户,因此你需要处理。
扩展
构造函数
new CredentialsSignin(message, errorOptions)
new CredentialsSignin(message?, errorOptions?): CredentialsSignin参数
| 参数 | 类型 |
|---|---|
message? | string | ErrorOptions |
errorOptions? | ErrorOptions |
返回值
继承自
属性
cause?
optional cause: Record<string, unknown> & {
err: Error;
};类型声明
err?
optional err: Error;继承自
code
code: string;在重定向 URL 的 code 查询参数中设置的错误代码。
⚠ 注意:此属性将包含在 URL 中,因此请确保它不暗示敏感错误。
如果需要调试,完整的错误始终会记录在服务器上。
通常,我们不建议明确提示用户是否错误输入了用户名或密码,而是尝试使用类似“无效凭据”的提示。
message
message: string;继承自
name
name: string;继承自
stack?
optional stack: string;继承自
type
type: ErrorType;错误类型。用于识别日志中的错误。
继承自
kind
static kind: string;继承自
prepareStackTrace()?
static optional prepareStackTrace: (err, stackTraces) => any;格式化堆栈跟踪的可选重写
参见
https://v8.node.org.cn/docs/stack-trace-api#customizing-stack-traces
参数
| 参数 | 类型 |
|---|---|
err | Error |
stackTraces | CallSite[] |
返回值
any
继承自
stackTraceLimit
static stackTraceLimit: number;继承自
type
static type: string;方法
captureStackTrace()
static captureStackTrace(targetObject, constructorOpt?): void在目标对象上创建 .stack 属性
参数
| 参数 | 类型 |
|---|---|
targetObject | object |
constructorOpt? | Function |
返回值
void
继承自
Account
通常包含有关所用提供者的信息,并且还扩展了 TokenSet,它是 OAuth 提供者返回的不同令牌。
扩展
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.oauth.ac.cn/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.oauth.ac.cn/reference/core/providers
providerAccountId
providerAccountId: string;此值取决于用于创建帐户的提供者类型。
- oauth/oidc:OAuth 帐户的 ID,从
profile()回调中返回。 - email:用户的电子邮件地址。
- credentials:从
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.oauth.ac.cn/reference/core/adapters#adapteruser
DefaultSession
扩展
属性
expires
expires: string;user?
optional user: User;Profile
从您的 OAuth 提供者返回的用户资料。
参见
https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
可索引的
[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;QwikAuthConfig
配置 QwikAuth$ 方法。
扩展
Omit<AuthConfig,"raw">
属性
adapter?
optional adapter: Adapter;您可以使用 adapter 选项传递您的数据库适配器。
继承自
Omit.adapter
basePath?
optional basePath: string;Auth.js API 端点的基本路径。
默认
"/api/auth" in "next-auth"; "/auth" with all other frameworks继承自
Omit.basePath
callbacks?
optional callbacks: {
jwt: (params) => Awaitable<null | JWT>;
redirect: (params) => Awaitable<string>;
session: (params) => Awaitable<Session | DefaultSession>;
signIn: (params) => Awaitable<string | boolean>;
};回调是异步函数,您可以使用它们来控制执行操作时发生的情况。回调非常强大,尤其是在涉及 JSON Web Tokens 的情况下,因为它们允许您在没有数据库的情况下实现访问控制,以及与外部数据库或 API 集成。
jwt()?
optional jwt: (params) => Awaitable<null | JWT>;每当创建 JSON Web Token(例如,在登录时)或更新 JSON Web Token(例如,在客户端访问会话时)时,都会调用此回调。您在此处返回的任何内容都将保存在 JWT 中并转发到会话回调。在那里,您可以控制应该返回给客户端的内容。任何其他内容都将从您的前端保留。JWT 默认通过您的 AUTH_SECRET 环境变量进行加密。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
params | 对象 | - |
params.account? | null | Account | 包含有关用于登录的提供者的信息。 还包括 TokenSet 注意 当 trigger 为 "signIn" 或 "signUp" 时可用 |
params.isNewUser? | 布尔值 | 已弃用 改用 trigger === "signUp" |
params.profile? | Profile | 从您的提供者返回的 OAuth 个人资料。 (在 OIDC 的情况下,它将是解码的 ID Token 或 /userinfo 响应) 注意 当 trigger 为 "signIn" 时可用。 |
params.session? | any | 当使用 AuthConfig.session strategy: "jwt" 时,这是数据从客户端通过 useSession().update 方法发送。⚠ 注意,您应该在使用此数据之前对其进行验证。 |
params.token | JWT | 当 trigger 为 "signIn" 或 "signUp" 时,它将是 JWT 的子集,name、email 和 image 将被包含。否则,它将是后续调用的完整 JWT。 |
params.trigger? | "update" | "signIn" | "signUp" | 检查 JWT 回调被调用的原因。可能的原因是 - 用户登录:回调首次被调用时, user、profile 和 account 将存在。- 用户注册:用户在数据库中首次创建(当 AuthConfig.session.strategy 设置为 "database" 时)- 更新事件:由 useSession().update 方法触发。在后者的 경우, trigger 将为 undefined。 |
params.user | User | AdapterUser | OAuthConfig.profile 或 CredentialsConfig.authorize 回调的结果。 注意 当 trigger 为 "signIn" 或 "signUp" 时可用。资源 - 凭据提供者 - 用户数据库模型 |
返回值
redirect()?
optional redirect: (params) => Awaitable<string>;每当用户被重定向到回调 URL(例如,登录或注销)时,都会调用此回调。默认情况下,只允许与源相同的 host 上的 URL。您可以使用此回调来自定义该行为。
示例
callbacks: {
async redirect({ url, baseUrl }) {
// Allows relative callback URLs
if (url.startsWith("/")) return `${baseUrl}${url}`
// Allows callback URLs on the same origin
if (new URL(url).origin === baseUrl) return url
return baseUrl
}
}参数
| 参数 | 类型 | 描述 |
|---|---|---|
params | 对象 | - |
params.baseUrl | 字符串 | 网站的默认基本 URL(可用作回退) |
params.url | 字符串 | 客户端提供的回调 URL |
返回值
Awaitable<string>
session()?
optional session: (params) => Awaitable<Session | DefaultSession>;每当检查会话时都会调用此回调。(例如,当调用 /api/session 端点、使用 useSession 或 getSession 时)。返回值将公开给客户端,因此请谨慎返回!如果您想向客户端提供您通过 JWT 回调添加到令牌中的任何内容,您必须在此处明确地返回它。
⚠ 默认情况下,出于安全考虑,只返回令牌的子集(电子邮件、名称、图像)。
token 参数仅在使用 jwt 会话策略时可用,user 参数仅在使用数据库会话策略时可用。
示例
callbacks: {
async session({ session, token, user }) {
// Send properties to the client, like an access_token from a provider.
session.accessToken = token.accessToken
return session
}
}参数
| 参数 | 类型 |
|---|---|
params | { session: { user: AdapterUser; } & AdapterSession; user: AdapterUser; } & { session: Session; token: JWT; } & { newSession: any; trigger: "update"; } |
返回值
Awaitable<Session | DefaultSession>
signIn()?
optional signIn: (params) => Awaitable<string | boolean>;控制用户是否可以登录。返回 true 将继续登录流程。返回 false 或抛出错误将停止登录流程并将用户重定向到错误页面。返回字符串将把用户重定向到指定的 URL。
未处理的错误将抛出一个 AccessDenied,其消息设置为原始错误。
示例
callbacks: {
async signIn({ profile }) {
// Only allow sign in for users with email addresses ending with "yourdomain.com"
return profile?.email?.endsWith("@yourdomain.com")
}参数
| 参数 | 类型 | 描述 |
|---|---|---|
params | 对象 | - |
params.account? | null | Account | - |
params.credentials? | Record<string, CredentialInput> | 如果使用凭据提供者,它将包含用户凭据 |
params.email? | 对象 | 如果使用电子邮件提供者,则在第一次调用时,它将包含一个verificationRequest: true 属性,以指示它是在验证请求流程中触发的。当用户单击登录链接后回调被调用时, 此属性将不存在。您可以检查 verificationRequest 属性以避免向阻止列表中的地址或域发送电子邮件,或仅显式地为其生成电子邮件 以允许列表中的电子邮件地址。 |
params.email.verificationRequest? | 布尔值 | - |
params.profile? | Profile | 如果使用 OAuth 提供者,它将包含完整的 您的提供者返回的 OAuth 个人资料。 |
params.user | User | AdapterUser | - |
返回值
Awaitable<string | boolean>
继承自
Omit.callbacks
cookies?
optional cookies: Partial<CookiesOptions>;您可以覆盖 Auth.js 使用的任何 cookie 的默认 cookie 名称和选项。您可以使用自定义属性指定一个或多个 cookie,缺少的选项将使用 Auth.js 定义的默认值。如果您使用此功能,您可能需要创建条件行为以支持在开发和生产构建中设置不同的 cookie 策略,因为您将选择退出内置的动态策略。
- ⚠ 这是一个高级选项。高级选项以与基本选项相同的方式传递,但可能具有复杂的影响或副作用。除非您非常习惯使用高级选项,否则您应该尝试避免使用高级选项。
默认值
{}继承自
Omit.cookies
debug?
optional debug: boolean;将 debug 设置为 true 以启用身份验证和数据库操作的调试消息。
- ⚠ 如果您添加了自定义的 AuthConfig.logger,则此设置将被忽略。
默认值
false继承自
Omit.debug
events?
optional events: {
createUser: (message) => Awaitable<void>;
linkAccount: (message) => Awaitable<void>;
session: (message) => Awaitable<void>;
signIn: (message) => Awaitable<void>;
signOut: (message) => Awaitable<void>;
updateUser: (message) => Awaitable<void>;
};事件是异步函数,不会返回响应,它们对于审计日志很有用。您可以为以下任何事件指定一个处理程序 - 例如,用于调试或创建审计日志。消息对象的內容因流程而异(例如,OAuth 或电子邮件身份验证流程、JWT 或数据库会话等),但通常包含用户对象和/或 JSON Web 令牌的内容以及与事件相关的其他信息。
默认值
{}createUser()?
optional createUser: (message) => Awaitable<void>;参数
| 参数 | 类型 |
|---|---|
message | 对象 |
message.user | User |
返回值
Awaitable<void>
linkAccount()?
optional linkAccount: (message) => Awaitable<void>;参数
| 参数 | 类型 |
|---|---|
message | 对象 |
message.account | Account |
message.profile | User | AdapterUser |
message.user | User | AdapterUser |
返回值
Awaitable<void>
session()?
optional session: (message) => Awaitable<void>;消息对象将包含以下内容之一,具体取决于您使用 JWT 还是数据库持久会话
token: 此会话的 JWT。session: 来自您适配器的会话对象。
参数
| 参数 | 类型 |
|---|---|
message | 对象 |
message.session | Session |
message.token | JWT |
返回值
Awaitable<void>
signIn()?
optional signIn: (message) => Awaitable<void>;如果使用 credentials 类型身份验证,则用户是来自您的凭据提供程序的原始响应。对于其他提供商,您将从适配器、帐户获取用户对象,以及指示用户是否是您的适配器的新用户。
参数
| 参数 | 类型 |
|---|---|
message | 对象 |
message.account? | null | Account |
message.isNewUser? | 布尔值 |
message.profile? | Profile |
message.user | User |
返回值
Awaitable<void>
signOut()?
optional signOut: (message) => Awaitable<void>;消息对象将包含以下内容之一,具体取决于您使用 JWT 还是数据库持久会话
token: 此会话的 JWT。session: 来自您的适配器的正在结束的会话对象。
参数
| 参数 | 类型 |
|---|---|
message | { session: undefined | null | void | AdapterSession; } | { token: null | JWT; } |
返回值
Awaitable<void>
updateUser()?
optional updateUser: (message) => Awaitable<void>;参数
| 参数 | 类型 |
|---|---|
message | 对象 |
message.user | User |
返回值
Awaitable<void>
继承自
Omit.events
experimental?
optional experimental: {
enableWebAuthn: boolean;
};使用此选项启用实验性功能。启用后,它将向控制台打印警告消息。
注意
实验性功能不保证稳定,可能会在未经通知的情况下更改或删除。请谨慎使用。
默认值
{}enableWebAuthn?
optional enableWebAuthn: boolean;启用 WebAuthn 支持。
默认值
false继承自
Omit.experimental
jwt?
optional jwt: Partial<JWTOptions>;如果您未指定 AuthConfig.adapter,则默认情况下启用 JSON Web 令牌。JSON Web 令牌默认情况下是加密的 (JWE)。我们建议您保留此行为。
继承自
Omit.jwt
logger?
optional logger: Partial<LoggerInstance>;覆盖任何日志记录级别(undefined 级别将使用内置日志记录器),并在 NextAuth 中拦截日志。您可以使用此选项将 NextAuth 日志发送到第三方日志记录服务。
示例
// /auth.ts
import log from "logging-service"
export const { handlers, auth, signIn, signOut } = NextAuth({
logger: {
error(code, ...message) {
log.error(code, message)
},
warn(code, ...message) {
log.warn(code, message)
},
debug(code, ...message) {
log.debug(code, message)
}
}
})- ⚠ 设置后,AuthConfig.debug 选项将被忽略
默认值
console继承自
Omit.logger
pages?
optional pages: Partial<PagesOptions>;如果您想创建自定义登录、登出和错误页面,请指定 URL。指定的页面将覆盖相应的内置页面。
默认值
{}示例
pages: {
signIn: '/auth/signin',
signOut: '/auth/signout',
error: '/auth/error',
verifyRequest: '/auth/verify-request',
newUser: '/auth/new-user'
}继承自
Omit.pages
providers
providers: Provider[];用于登录的身份验证提供商列表(例如 Google、Facebook、Twitter、GitHub、电子邮件等),顺序任意。这可以是内置提供商之一,也可以是包含自定义提供商的对象。
默认值
[]继承自
Omit.providers
redirectProxyUrl?
optional redirectProxyUrl: string;设置后,在 OAuth 登录流程期间,授权请求的 redirect_uri 将根据此值设置。
如果您 OAuth 提供商仅支持单个 redirect_uri 或者您希望在预览 URL(如 Vercel)上使用 OAuth(您事先不知道最终部署 URL),这将很有用。
url 需要包含完整路径,直到初始化 Auth.js 的位置。
注意
这将自动在提供商上启用 state OAuth2Config.checks。
示例
"https://authjs.example.com/api/auth"您也可以为每个提供商分别覆盖此项。
示例
GitHub({
...
redirectProxyUrl: "https://github.example.com/api/auth"
})默认值
AUTH_REDIRECT_PROXY_URL 环境变量
另请参阅:指南:保护预览部署
继承自
Omit.redirectProxyUrl
secret?
optional secret: string | string[];用于哈希令牌、签名 cookie 和生成加密密钥的随机字符串。
要生成随机字符串,您可以使用 Auth.js CLI:npx auth secret
注意
您也可以传递一个密钥数组,在这种情况下,第一个成功解密 JWT 的密钥将被使用。这对于在不使现有会话失效的情况下轮换密钥很有用。较新的密钥应添加到数组的开头,这将用于所有新会话。
继承自
Omit.secret
session?
optional session: {
generateSessionToken: () => string;
maxAge: number;
strategy: "jwt" | "database";
updateAge: number;
};配置您的会话,例如您想使用 JWT 还是数据库,空闲会话过期需要多长时间,或者在使用数据库时限制写入操作。
generateSessionToken()?
optional generateSessionToken: () => string;为基于数据库的会话生成自定义会话令牌。默认情况下,将生成一个随机 UUID 或字符串,具体取决于 Node.js 版本。但是,您可以指定自己的自定义字符串(例如 CUID)来使用。
默认值
randomUUID 或 randomBytes.toHex,具体取决于 Node.js 版本
返回值
字符串
maxAge?
optional maxAge: number;从现在起以秒为单位的相对时间,会话将在该时间过期
默认值
2592000 // 30 daysstrategy?
optional strategy: "jwt" | "database";选择您要保存用户会话的方式。默认值为 "jwt",即会话 cookie 中的加密 JWT (JWE)。
但是,如果您使用 adapter,我们将将其默认设置为 "database"。您仍然可以通过显式定义 "jwt" 强制使用 JWT 会话。
使用 "database" 时,会话 cookie 仅包含 sessionToken 值,用于在数据库中查找会话。
文档 | 适配器 | 关于 JSON Web 令牌
updateAge?
optional updateAge: number;会话更新频率(秒)。如果设置为 0,则每次都会更新会话。
默认值
86400 // 1 day继承自
Omit.session
skipCSRFCheck?
optional skipCSRFCheck: typeof skipCSRFCheck;继承自
Omit.skipCSRFCheck
theme?
optional theme: Theme;更改内置 AuthConfig.pages 的主题。
继承自
Omit.theme
trustHost?
optional trustHost: boolean;Auth.js 依赖于传入请求的 host 标头才能正常运行。因此,此属性需要设置为 true。
确保您的部署平台安全地设置了 host 标头。
基于 Auth.js 的官方库会尝试为一些已知会安全设置 host 标头的部署平台(例如:Vercel)自动设置此值。
继承自
Omit.trustHost
useSecureCookies?
optional useSecureCookies: boolean;当设置为 true 时,NextAuth.js 设置的所有 cookie 只能从 HTTPS URL 访问。此选项默认为 false,用于以 http:// 开头的 URL(例如 https://:3000),方便开发者。您可以手动将此选项设置为 false 来禁用此安全功能,并允许从非安全 URL 访问 cookie(不建议这样做)。
- ⚠ 这是一个高级选项。高级选项以与基本选项相同的方式传递,但可能具有复杂的影响或副作用。除非您非常习惯使用高级选项,否则您应该尝试避免使用高级选项。
默认值为 HTTP 上的 false 和 HTTPS 站点上的 true。
继承自
Omit.useSecureCookies
会话
登录用户的活动会话。
扩展
属性
expires
expires: string;继承自
user?
optional user: User;继承自
用户
OAuth 提供商 profile 回调中返回的对象的形状,在 jwt 和 session 回调中可用,或者使用数据库时 session 回调的第二个参数。
属性
email?
optional email: null | string;id?
optional id: string;image?
optional image: null | string;name?
optional name: null | string;GetSessionResult
type GetSessionResult: Promise<{
cookie: any;
data: Session | null;
}>;类型声明
cookie
cookie: any;data
data: Session | null;customFetch
const customFetch: unique symbol;此选项允许您覆盖提供商用于直接向提供商的 OAuth 端点发出请求的默认 fetch 函数。如果使用不当,会导致安全问题。
它可以用于支持企业代理、自定义获取库、缓存发现端点、添加测试模拟、记录、为不符合规范的提供商设置自定义标头/参数等。
示例
import { Auth, customFetch } from "@auth/core"
import GitHub from "@auth/core/providers/github"
const dispatcher = new ProxyAgent("my.proxy.server")
function proxy(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {
return undici(args[0], { ...(args[1] ?? {}), dispatcher })
}
const response = await Auth(request, {
providers: [GitHub({ [customFetch]: proxy })]
})参见
- https://undici.nodejs.org/#/docs/api/ProxyAgent?id=example-basic-proxy-request-with-local-agent-dispatcher
- https://authjs.oauth.ac.cn/guides/corporate-proxy
QwikAuth$()
QwikAuth$(qrl, ...rest): {
onRequest: (req) => Promise<void>;
useSession: Loader_2<null | Session>;
useSignIn: Action<{
failed: undefined;
fieldErrors: undefined;
formErrors: undefined;
} | {
failed: true;
fieldErrors: {
authorizationParams: undefined | string[];
options: undefined | string[];
providerId: undefined | string[];
redirectTo: undefined | string[];
};
formErrors: string[];
}, {
authorizationParams: string | URLSearchParams | Record<string, string>;
options: objectOutputType<{
redirectTo: ZodOptional<ZodString>;
}, ZodTypeAny, "passthrough">;
providerId: string;
redirectTo: string;
}, false>;
useSignOut: Action<{
failed: undefined;
fieldErrors: undefined;
formErrors: undefined;
} | {
failed: true;
fieldErrors: {
redirectTo: undefined | string[];
};
formErrors: string[];
}, {
redirectTo: string;
}, false>;
}初始化 Qwik Auth。
参数
| 参数 | 类型 |
|---|---|
qrl | (ev) => QwikAuthConfig |
…rest | [] |
返回值
{
onRequest: (req) => Promise<void>;
useSession: Loader_2<null | Session>;
useSignIn: Action<{
failed: undefined;
fieldErrors: undefined;
formErrors: undefined;
} | {
failed: true;
fieldErrors: {
authorizationParams: undefined | string[];
options: undefined | string[];
providerId: undefined | string[];
redirectTo: undefined | string[];
};
formErrors: string[];
}, {
authorizationParams: string | URLSearchParams | Record<string, string>;
options: objectOutputType<{
redirectTo: ZodOptional<ZodString>;
}, ZodTypeAny, "passthrough">;
providerId: string;
redirectTo: string;
}, false>;
useSignOut: Action<{
failed: undefined;
fieldErrors: undefined;
formErrors: undefined;
} | {
failed: true;
fieldErrors: {
redirectTo: undefined | string[];
};
formErrors: string[];
}, {
redirectTo: string;
}, false>;
}onRequest()
onRequest: (req) => Promise<void>;参数
| 参数 | 类型 |
|---|---|
req | RequestEventCommon<QwikCityPlatform> |
返回值
Promise<void>
useSession
useSession: Loader_2<null | Session>;useSignIn
useSignIn: Action<{
failed: undefined;
fieldErrors: undefined;
formErrors: undefined;
} | {
failed: true;
fieldErrors: {
authorizationParams: undefined | string[];
options: undefined | string[];
providerId: undefined | string[];
redirectTo: undefined | string[];
};
formErrors: string[];
}, {
authorizationParams: string | URLSearchParams | Record<string, string>;
options: objectOutputType<{
redirectTo: ZodOptional<ZodString>;
}, ZodTypeAny, "passthrough">;
providerId: string;
redirectTo: string;
}, false>;useSignOut
useSignOut: Action<{
failed: undefined;
fieldErrors: undefined;
formErrors: undefined;
} | {
failed: true;
fieldErrors: {
redirectTo: undefined | string[];
};
formErrors: string[];
}, {
redirectTo: string;
}, false>;示例
import { QwikAuth } from "@auth/qwik"
import GitHub from "@auth/qwik/providers/github"
export const {
onRequest, useSession, useSignIn, useSignOut
} = QwikAuth$(() => ({ providers: [GitHub] }))setEnvDefaults()
setEnvDefaults(env, config): void参数
| 参数 | 类型 |
|---|---|
env | EnvGetter |
config | AuthConfig |
返回值
void