Firebase 驗證
函式
等級
類別 | 說明 |
---|---|
ActionCodeURL | 可剖析電子郵件動作網址的公用程式類別,例如密碼重設、電子郵件驗證、電子郵件連結登入等。 |
AuthCredential | 代表 AuthProvider 傳回憑證的介面。 |
EmailAuthCredential | 代表 EmailAuthProvider 針對 ProviderId 傳回的憑證的介面。PASSWORD |
EmailAuthProvider | 產生 EmailAuthCredential 的提供者。 |
FacebookAuthProvider | 為 ProviderId.FACEBOOK 產生 OAuthCredential 的提供者。 |
GitHub | 為 ProviderId.GITHUB 產生 OAuthCredential 的提供者。 |
GoogleAuthProvider | 為 ProviderId.GOOGLE 產生 OAuthCredential 的提供者。 |
OAuth 憑證 | 代表 OAuthProvider 傳回的 OAuth 憑證。 |
OAuthProvider | 產生一般 OAuthCredential 的提供者。 |
PhoneAuthCredential | 代表 PhoneAuthProvider 傳回的憑證。 |
PhoneAuthProvider | 產生 PhoneAuthCredential 的提供者。 |
PhoneMultiFactorGenerator | 產生 PhoneMultiFactorAssertion 的提供者。 |
reCAPTCHA 驗證器 | 以 reCAPTCHA 為基礎的應用程式驗證器。 |
SAMLAuthProvider | SAML 的 AuthProvider。 |
TotpMultiFactorGenerator | 產生 TotpMultiFactorAssertion 的提供者。 |
TotpSecret | 產生 TotpMultiFactorAssertion 的提供者。儲存共用密鑰和其他參數,以產生時間型動態密碼。實作擷取共用密鑰及產生 QR code 網址的方法。 |
TwitterAuthProvider | 為 ProviderId.TWITTER 產生 OAuthCredential 的提供者。 |
介面
介面 | 說明 |
---|---|
ActionCodeInfo | checkActionCode() 的回應。 |
ActionCodeSettings | 這個介面會定義必要的繼續/狀態網址,並包含選用的 Android 和 iOS 軟體包 ID。 |
其他使用者資訊 | 包含聯合識別資訊提供者提供的其他使用者資訊的結構。 |
ApplicationVerifier | 驗證網域及防範濫用行為的驗證器。 |
驗證 | 代表 Firebase 驗證服務的介面。 |
AuthError | Auth 錯誤的介面。 |
AuthErrorMap | 錯誤代碼與錯誤訊息的對應。 |
AuthProvider | 代表驗證提供者的介面,用於建立 AuthCredential。 |
AuthSettings | 代表 Auth 執行個體設定的介面。 |
設定 | 代表 Auth 設定的介面。 |
ConfirmationResult | 電話號碼登入、連結或重新驗證通話的結果。 |
依附元件 | 可用來初始化 Auth 執行個體的依附元件。 |
EmulatorConfig | 設定 Firebase 驗證模擬器。 |
IdTokenResult | 代表 ID 權杖結果 (從 User.getIdTokenResult() 取得) 的介面。 |
MultiFactorAssertion | 用來宣告第二項因素擁有權的基礎類別。 |
MultiFactorError | 如果使用者需要提供第二項因素才能成功登入,系統就會擲回錯誤。 |
MultiFactorInfo | 包含第二因素實體資訊的結構。 |
MultiFactorResolver | 在使用者需要提供登入的第二重驗證時,用於從 MultiFactorError 復原的類別。 |
MultiFactorSession | 用於定義使用者雙重驗證的多重因素工作階段物件,或協助透過雙重驗證登入已註冊使用者的介面。 |
多重因素使用者 | 這個介面用於定義與使用者相關的多因素相關屬性和作業。 |
OAuthCredentialOptions | 定義初始化 OAuthCredential 的選項。 |
ParsedToken | 代表已剖析 ID 權杖的介面。 |
PasswordPolicy | 指定密碼政策規定的結構。 |
PasswordValidationStatus | 用來表示符合或違反哪些密碼政策規定的結構。 |
持續保留 | 涵蓋可能持續性機制類型的介面。 |
PhoneMultiFactorAssertion | 用來宣告手機雙重驗證擁有權的類別。由 PhoneMultiFactorGenerator.assertion() 提供。 |
PhoneMultiFactorEnrollmentInfoOptions | 雙重驗證的註冊選項。 |
PhoneMultiFactorInfo | 電話號碼第二項因素的 MultiFactorInfo 介面子類別。第二個因素的 factorId 為 FactorId.PHONE。 |
PhoneMultiFactorSignInInfoOptions | 透過第二重驗證方式登入的選項。 |
PhoneSingleFactorInfoOptions | 單因素登入時使用的選項。 |
PopupRedirectResolver | 一種解析器,用於處理 DOM 特定作業,例如 signInWithPopup() 或 signInWithRedirect()。 |
ReactNativeAsyncStorage | 所提供 AsyncStorage 的介面。 |
RecaptchaParameters | 代表 reCAPTCHA 參數的介面。如需系統接受的參數清單,請參閱 reCAPTCHA 文件。可接受 sitekey 以外的所有參數:Firebase 驗證會為每項專案佈建 reCAPTCHA,並在算繪時設定網站金鑰。如為隱藏的 reCAPTCHA,請將 size 金鑰設為「invisible 」。 |
TotpMultiFactorAssertion | 宣告 TOTP 雙重驗證擁有權的類別。由 TotpMultiFactorGenerator.assertionForEnrollment() 和 TotpMultiFactorGenerator.assertionForSignIn() 提供。 |
TotpMultiFactorInfo | TOTP 第二因素的 MultiFactorInfo 介面子類別。第二個因素的 factorId 為 FactorId.TOTP。 |
User | 使用者帳戶。 |
使用者憑證 | 包含「使用者」、「OperationType」 和提供者 ID 的結構。 |
UserInfo | 使用者個人資料資訊,只有 Firebase 專案的應用程式看得到。 |
使用者中繼資料 | 代表使用者中繼資料的介面。 |
變數
變數 | 說明 |
---|---|
ActionCodeOperation | 可能的電子郵件動作型別列舉。 |
AuthErrorCodes | 潛在 Auth 錯誤代碼的對應,方便比較 SDK 擲回的錯誤。 |
browserLocalPersistence | 使用 localStorage 做為基礎儲存空間,實作 LOCAL 類型的持續性實作。 |
browserPopupRedirectResolver | 適用於瀏覽器應用程式的 PopupRedirectResolver 實作。 |
browserSessionPersistence | 使用 sessionStorage 做為基礎儲存空間的 SESSION 持續性實作。 |
cordovaPopupRedirectResolver | 適用於 Cordova 型應用程式的 PopupRedirectResolver 實作。 |
debugErrorMap | 詳細的錯誤地圖,其中含有多數錯誤代碼的詳細說明。請參閱 AuthErrorMap 中的討論 |
FactorId | 可用於多重驗證的因素列舉。 |
indexedDBLocalPersistence | 使用 indexedDB 做為基礎儲存空間,實作 LOCAL 類型的持續性實作。 |
inMemoryPersistence | 「NONE」類型的持續性實作。 |
作業類型 | 支援的作業類型的列舉。 |
prodErrorMap | 最小的錯誤地圖,其中已移除所有詳細錯誤訊息。請參閱 AuthErrorMap 中的討論 |
ProviderId (供應商 ID) | 支援提供者的列舉。 |
SignInMethod | 支援的登入方法列舉。 |
類型別名
類型別名 | 說明 |
---|---|
自訂參數 | OAuth 自訂參數對應。 |
NextOrObserver | 事件回呼的類型定義。 |
PhoneInfoOptions | 驗證電話號碼擁有權所需的資訊。 |
使用者個人資料 | AdditionalUserInfo 中使用的使用者個人資料。 |
function(app, ...)
getAuth(應用程式)
傳回與提供的 FirebaseApp 相關聯的驗證執行個體。如果沒有執行個體,請使用平台專屬的預設依附元件初始化 Auth 執行個體。
簽名:
export declare function getAuth(app?: FirebaseApp): Auth;
參數
參數 | 類型 | 說明 |
---|---|---|
app | Firebase 應用程式 | Firebase 應用程式。 |
傳回:
InitialAuth(應用程式, deps)
初始化 Auth 執行個體,且能精細控管「依附元件」。
這個函式可讓您進一步控管 Auth 執行個體,比 getAuth()。getAuth
會使用平台專屬的預設值來提供依附元件。一般來說,getAuth
是初始化驗證最簡單的方法,適用於大多數用途。如果您需要控管使用的持久層,請使用 initializeAuth
;如果未使用 signInWithPopup
或 signInWithRedirect
,則可最小化套件大小。
舉例來說,如果您的應用程式只使用匿名帳戶,而且只想針對目前工作階段儲存帳戶,請用下列方式初始化 Auth
:
const auth = initializeAuth(app, {
persistence: browserSessionPersistence,
popupRedirectResolver: undefined,
});
簽名:
export declare function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth;
參數
參數 | 類型 | 說明 |
---|---|---|
app | Firebase 應用程式 | |
deps | 依附元件 |
傳回:
function(儲存空間, ...)
getReactNativePersistence(儲存空間)
回傳持續性物件,該物件會納入從 react-native
或 @react-native-community/async-storage
匯入的 AsyncStorage
,且可用於 InitialAuth() 的持續性依附元件欄位。
簽名:
export declare function getReactNativePersistence(storage: ReactNativeAsyncStorage): Persistence;
參數
參數 | 類型 | 說明 |
---|---|---|
儲存空間 | ReactNativeAsyncStorage |
傳回:
function(驗證, ...)
applyActionCode(auth, oobCode)
套用透過電子郵件或其他頻外機制傳送給使用者的驗證碼。
簽名:
export declare function applyActionCode(auth: Auth, oobCode: string): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
oobCode | 字串 | 傳送給使用者的驗證碼。 |
傳回:
承諾<void>
beforeAuthStateChanged(驗證, 回呼, onAbort)
新增在驗證狀態變更設定新使用者之前執行的封鎖回呼,以便設定新使用者。
簽名:
export declare function beforeAuthStateChanged(auth: Auth, callback: (user: User | null) => void | Promise<void>, onAbort?: () => void): Unsubscribe;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
回呼 | (使用者:User | null) => void | Promise<void> | 會在設定新使用者值之前觸發回呼。如果擲回這則訊息,系統會禁止使用者設定。 |
onAbort | () => void | 當較新的 beforeAuthStateChanged() 回呼擲回時,會觸發回呼,以便您復原任何副作用。 |
傳回:
checkActionCode(auth, oobCode)
檢查透過電子郵件或其他頻外機制傳送給使用者的驗證碼。
簽名:
export declare function checkActionCode(auth: Auth, oobCode: string): Promise<ActionCodeInfo>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
oobCode | 字串 | 傳送給使用者的驗證碼。 |
傳回:
Promise<ActionCodeInfo>
有關程式碼的中繼資料
確認密碼重設(auth, oobCode, newPassword)
取得確認碼和新密碼,完成密碼重設程序。
簽名:
export declare function confirmPasswordReset(auth: Auth, oobCode: string, newPassword: string): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
oobCode | 字串 | 傳送給使用者的確認碼。 |
新密碼 | 字串 | 新密碼。 |
傳回:
承諾<void>
linkAuthEmulator(auth, url, options)
變更 Auth 執行個體,與 Firebase 驗證模擬器通訊,而非正式版 Firebase 驗證服務。
您必須在第一次呼叫 initializeAuth() 後以同步方式呼叫這項呼叫。請勿與正式版憑證搭配使用,因為模擬器流量未經加密。
簽名:
export declare function connectAuthEmulator(auth: Auth, url: string, options?: {
disableWarnings: boolean;
}): void;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
網址 | 字串 | 執行模擬器的網址 (例如「http://localhost:9099」)。 |
選項 | { disableWarnings: boolean; } | 選用設定。options.disableWarnings 預設為 false 。設為 true 即可停用附加至 DOM 的警告橫幅。 |
傳回:
無效
範例
connectAuthEmulator(auth, 'http://127.0.0.1:9099', { disableWarnings: true });
createUserWithEmailAndPassword(驗證, 電子郵件, 密碼)
以指定電子郵件地址和密碼建立新的使用者帳戶。
成功建立使用者帳戶後,這位使用者也將登入您的應用程式。
如果帳戶已存在或是密碼無效,使用者帳戶建立作業可能會失敗。
使用 FirebaseServerApp 建立的 Auth 執行個體不支援這個方法。
簽名:
export declare function createUserWithEmailAndPassword(auth: Auth, email: string, password: string): Promise<UserCredential>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
字串 | 使用者的電子郵件地址。 | |
密碼 | 字串 | 使用者選擇的密碼。 |
傳回:
Promise<使用者憑證>
captureSignInMethodsForEmail(驗證、電子郵件)
取得指定電子郵件地址可能的登入方法清單。這個方法會在啟用電子郵件列舉防護時傳回空白清單,無論指定電子郵件可用的驗證方法為何。
這種做法有助於區分同一個供應商的登入方式,例如:EmailAuthProvider:有 2 種登入方法,分別是 SignInMethod.EMAIL_PASSWORD 和 SignInMethod.EMAIL_LINK。
簽名:
export declare function fetchSignInMethodsForEmail(auth: Auth, email: string): Promise<string[]>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
字串 | 使用者的電子郵件地址。已淘汰。建議您停用這個方法,因為這是安全性最佳做法。詳情請參閱 Identity Platform 的電子郵件列舉防護說明文件。 |
傳回:
Promise<string[]>
getMultiFactorResolver(驗證, 錯誤)
提供適合完成多重因素流程的 MultiFactorResolver。
簽名:
export declare function getMultiFactorResolver(auth: Auth, error: MultiFactorError): MultiFactorResolver;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
錯誤 | MultiFactorError | 在登入或重新驗證作業期間產生的 MultiFactorError。 |
傳回:
getRedirectResult(auth, 解析器)
從重新導向的登入流程傳回 UserCredential。
如果登入成功,則傳回登入的使用者。如果登入失敗,則會發生錯誤。如未呼叫任何重新導向作業,則會傳回 null
。
這個方法不適用於 Node.js 環境,或是以 FirebaseServerApp 建立的 Auth 執行個體。
簽名:
export declare function getRedirectResult(auth: Auth, resolver?: PopupRedirectResolver): Promise<UserCredential | null>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
解析器 | PopupRedirectResolver | PopupRedirectResolver 的執行個體,如果已提供至 initializeAuth() 或由 getAuth() 提供,則為選用。 |
傳回:
Promise<UserCredential | null>
範例
// Sign in using a redirect.
const provider = new FacebookAuthProvider();
// You can add additional scopes to the provider:
provider.addScope('user_birthday');
// Start a sign in process for an unauthenticated user.
await signInWithRedirect(auth, provider);
// This will trigger a full page redirect away from your app
// After returning from the redirect when your app initializes you can obtain the result
const result = await getRedirectResult(auth);
if (result) {
// This is the signed-in user
const user = result.user;
// This gives you a Facebook Access Token.
const credential = provider.credentialFromResult(auth, result);
const token = credential.accessToken;
}
// As this API can be used for sign-in, linking and reauthentication,
// check the operationType to determine what triggered this redirect
// operation.
const operationType = result.operationType;
InitialRecaptchaConfig(auth)
將 reCAPTCHA 設定載入 Auth
執行個體。
這項操作會載入 reCAPTCHA 設定,表示是否應對每個驗證服務供應商觸發 reCAPTCHA 驗證流程,並進入目前的驗證工作階段。
如未叫用 initializeRecaptchaConfig(),系統將一律在驗證流程啟動時,無需進行 reCAPTCHA 驗證。如果供應商設為需要 reCAPTCHA 驗證,SDK 就會以公開透明的方式載入 reCAPTCHA 設定,並重新啟動驗證流程。
因此,只要呼叫這個選用方法,您就能減少未來驗證流程的延遲時間。及早載入 reCAPTCHA 設定也能強化 reCAPTCHA 收集的信號。
這個方法不適用於 Node.js 環境。
簽名:
export declare function initializeRecaptchaConfig(auth: Auth): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
傳回:
承諾<void>
範例
initializeRecaptchaConfig(auth);
isSignInWithEmailLink(驗證、電子郵件連結)
檢查傳入連結是否為使用電子郵件連結登入的登入,適用於 signInWithEmailLink()。
簽名:
export declare function isSignInWithEmailLink(auth: Auth, emailLink: string): boolean;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
電子郵件連結 | 字串 | 傳送至使用者電子郵件地址的連結。 |
傳回:
布林值
onAuthStateChanged(auth, nextOrObserver, 錯誤, 已完成)
新增觀察器,觀察使用者登入狀態的變更。
如果想保留舊行為,請參閱 onIdTokenChanged()。
簽名:
export declare function onAuthStateChanged(auth: Auth, nextOrObserver: NextOrObserver<User>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
NextOrObserver | NextOrObserver<使用者> | 變更時觸發的回呼。 |
錯誤 | ErrorFn | 已淘汰,此回呼永遠不會觸發。我們會判斷登入/登出功能傳回的承諾,瞭解登入/登出錯誤。 |
已完成 | CompleteFn | 已淘汰,此回呼永遠不會觸發。 |
傳回:
onIdTokenChanged(auth, nextOrObserver, 錯誤, 已完成)
新增觀察器,瞭解對已登入使用者 ID 權杖的變更。
這包括登入、登出和權杖更新事件。ID 權杖到期後,系統不會自動觸發 ID。使用 User.getIdToken() 重新整理 ID 權杖。
簽名:
export declare function onIdTokenChanged(auth: Auth, nextOrObserver: NextOrObserver<User>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
NextOrObserver | NextOrObserver<使用者> | 變更時觸發的回呼。 |
錯誤 | ErrorFn | 已淘汰,此回呼永遠不會觸發。我們會判斷登入/登出功能傳回的承諾,瞭解登入/登出錯誤。 |
已完成 | CompleteFn | 已淘汰,此回呼永遠不會觸發。 |
傳回:
撤銷 AccessToken(auth, 權杖)
撤銷指定的存取權杖。目前僅支援 Apple OAuth 存取權杖。
簽名:
export declare function revokeAccessToken(auth: Auth, token: string): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
token | 字串 | Apple OAuth 存取權杖。 |
傳回:
承諾<void>
sendPasswordResetEmail(auth, email, actionCodeSettings)
將密碼重設電子郵件傳送至指定的電子郵件地址。在沒有具備指定電子郵件地址的使用者帳戶,且啟用了電子郵件列舉防護的情況下,這個方法不會擲回錯誤。
如要完成密碼重設,請使用傳送給使用者的電子郵件中提供的代碼呼叫 confirmPasswordReset(),以及使用者指定的新密碼。
簽名:
export declare function sendPasswordResetEmail(auth: Auth, email: string, actionCodeSettings?: ActionCodeSettings): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
字串 | 使用者的電子郵件地址。 | |
actionCodeSettings | ActionCodeSettings | ActionCodeSettings。 |
傳回:
承諾<void>
範例
const actionCodeSettings = {
url: 'https://www.example.com/?email=user@example.com',
iOS: {
bundleId: 'com.example.ios'
},
android: {
packageName: 'com.example.android',
installApp: true,
minimumVersion: '12'
},
handleCodeInApp: true
};
await sendPasswordResetEmail(auth, 'user@example.com', actionCodeSettings);
// Obtain code from user.
await confirmPasswordReset('user@example.com', code);
sendSignInLinkToEmail(auth, email, actionCodeSettings)
將登入電子郵件連結傳送給指定電子郵件地址的使用者。
與其他頻帶電子郵件動作 (密碼重設和電子郵件驗證) 不同,登入作業必須一律在應用程式中完成。這是因為流程結束時,使用者應使用者需要登入,且驗證狀態會保留在應用程式中。
如要透過電子郵件連結完成登入程序,請使用傳送給使用者的電子郵件地址和電子郵件連結呼叫 signInWithEmailLink()。
簽名:
export declare function sendSignInLinkToEmail(auth: Auth, email: string, actionCodeSettings: ActionCodeSettings): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | |
字串 | 使用者的電子郵件地址。 | |
actionCodeSettings | ActionCodeSettings | ActionCodeSettings。 |
傳回:
承諾<void>
範例
const actionCodeSettings = {
url: 'https://www.example.com/?email=user@example.com',
iOS: {
bundleId: 'com.example.ios'
},
android: {
packageName: 'com.example.android',
installApp: true,
minimumVersion: '12'
},
handleCodeInApp: true
};
await sendSignInLinkToEmail(auth, 'user@example.com', actionCodeSettings);
// Obtain emailLink from the user.
if(isSignInWithEmailLink(auth, emailLink)) {
await signInWithEmailLink(auth, 'user@example.com', emailLink);
}
setPersistence(驗證、持續性)
針對目前儲存的 Auth
工作階段,變更 Auth 執行個體的持續性類型,並將此類型的持續性套用至日後登入要求 (包括透過重新導向要求登入)。
這可方便使用者登入,指定是否要記住自己的工作階段。此外,對於由其他使用者共用或具備機密資料的應用程式,您也可以更輕鬆地保留 Auth
狀態。
這個方法不適用於 Node.js 環境,或是以 FirebaseServerApp 建立的 Auth 執行個體。
簽名:
export declare function setPersistence(auth: Auth, persistence: Persistence): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
持續性 | 持續保留 | 要使用的永久性。 |
傳回:
承諾<void>
持續性變更完成後,會解決的 Promise
範例
setPersistence(auth, browserSessionPersistence);
signInAnonymously(驗證)
以匿名使用者身分非同步登入。
如果已有匿名使用者登入,系統會傳回該使用者;否則,將建立新的匿名使用者身分。
使用 FirebaseServerApp 建立的 Auth 執行個體不支援這個方法。
簽名:
export declare function signInAnonymously(auth: Auth): Promise<UserCredential>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
傳回:
Promise<使用者憑證>
signInWithCredential(auth, 憑證)
使用指定憑證以非同步方式登入。
AuthProvider 可用來產生憑證,
使用 FirebaseServerApp 建立的 Auth 執行個體不支援這個方法。
簽名:
export declare function signInWithCredential(auth: Auth, credential: AuthCredential): Promise<UserCredential>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
憑證 | AuthCredential | 驗證憑證。 |
傳回:
Promise<使用者憑證>
signInWithCustomToken(auth, customToken)
使用自訂權杖,以非同步方式登入。
自訂權杖可用來整合 Firebase 驗證與現有驗證系統,而且必須由驗證後端使用 Admin SDK 中的 createCustomToken 方法產生。
Firebase 驗證服務無效、過期或未接受憑證,導致發生錯誤。
使用 FirebaseServerApp 建立的 Auth 執行個體不支援這個方法。
簽名:
export declare function signInWithCustomToken(auth: Auth, customToken: string): Promise<UserCredential>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
自訂符記 | 字串 | 用來登入的自訂權杖。 |
傳回:
Promise<使用者憑證>
signInWithEmailAndPassword(驗證, 電子郵件, 密碼)
使用電子郵件地址和密碼非同步登入。
若電子郵件地址和密碼不相符,系統將傳回錯誤。啟用電子郵件列舉防護後,如果電子郵件/密碼無效,此方法就會失敗並顯示「auth/invalid-credential」(驗證/無效憑證)。
使用 FirebaseServerApp 建立的 Auth 執行個體不支援這個方法。
簽名:
export declare function signInWithEmailAndPassword(auth: Auth, email: string, password: string): Promise<UserCredential>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
字串 | 使用者的電子郵件地址。 | |
密碼 | 字串 | 使用者密碼。 |
傳回:
Promise<使用者憑證>
signInWithEmailLink(驗證, 電子郵件, 電子郵件連結)
透過電子郵件和登入電子郵件連結,非同步登入。
如未傳送連結,系統會從目前的網址推測連結。
如果電子郵件地址無效或電子郵件連結中的動態密碼到期,就會發生錯誤。
使用 FirebaseServerApp 建立的 Auth 執行個體不支援這個方法。
簽名:
export declare function signInWithEmailLink(auth: Auth, email: string, emailLink?: string): Promise<UserCredential>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
字串 | 使用者的電子郵件地址。 | |
電子郵件連結 | 字串 | 傳送至使用者電子郵件地址的連結。 |
傳回:
Promise<使用者憑證>
範例
const actionCodeSettings = {
url: 'https://www.example.com/?email=user@example.com',
iOS: {
bundleId: 'com.example.ios'
},
android: {
packageName: 'com.example.android',
installApp: true,
minimumVersion: '12'
},
handleCodeInApp: true
};
await sendSignInLinkToEmail(auth, 'user@example.com', actionCodeSettings);
// Obtain emailLink from the user.
if(isSignInWithEmailLink(auth, emailLink)) {
await signInWithEmailLink(auth, 'user@example.com', emailLink);
}
signInWithPhoneNumber(auth, phoneNumber, appVerifier)
使用電話號碼非同步登入。
這個方法會透過簡訊將驗證碼傳送至指定電話號碼,並傳回 ConfirmationResult。在使用者提供傳送至手機的驗證碼後,呼叫 ConfirmationResult.confirm() 以及代碼,以便使用者登入。
為防範濫用行為,這個方法也需要使用 ApplicationVerifier。這個 SDK 包含以 reCAPTCHA 為基礎的實作 RecaptchaVerifier。這個函式可以在其他不支援 RecaptchaVerifier 的其他平台上 (例如 React Native),但必須使用第三方 ApplicationVerifier 實作。
這個方法不適用於 Node.js 環境,或是以 FirebaseServerApp 建立的 Auth 執行個體。
簽名:
export declare function signInWithPhoneNumber(auth: Auth, phoneNumber: string, appVerifier: ApplicationVerifier): Promise<ConfirmationResult>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
phoneNumber | 字串 | 使用者的電話號碼,格式為 E.164 (例如 +16505550101)。 |
應用程式驗證器 | ApplicationVerifier | ApplicationVerifier。 |
傳回:
Promise<ConfirmationResult>
範例
// 'recaptcha-container' is the ID of an element in the DOM.
const applicationVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container');
const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
// Obtain a verificationCode from the user.
const credential = await confirmationResult.confirm(verificationCode);
signInWithPopup(驗證, 供應商, 解析器)
使用彈出式視窗式 OAuth 驗證流程驗證 Firebase 用戶端。
如果成功,則會傳回已登入的使用者和提供者憑證。如果登入失敗,系統會傳回錯誤物件,其中包含與錯誤相關的其他資訊。
這個方法不適用於 Node.js 環境,或是以 FirebaseServerApp 建立的 Auth 執行個體。
簽名:
export declare function signInWithPopup(auth: Auth, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<UserCredential>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
提供者 | AuthProvider | 要驗證的供應商。提供者必須是 OAuthProvider。EmailAuthProvider 等非 OAuth 供應商則會擲回錯誤。 |
解析器 | PopupRedirectResolver | PopupRedirectResolver 的執行個體,如果已提供至 initializeAuth() 或由 getAuth() 提供,則為選用。 |
傳回:
Promise<使用者憑證>
範例
// Sign in using a popup.
const provider = new FacebookAuthProvider();
const result = await signInWithPopup(auth, provider);
// The signed-in user info.
const user = result.user;
// This gives you a Facebook Access Token.
const credential = provider.credentialFromResult(auth, result);
const token = credential.accessToken;
signInWithRedirect(驗證, 提供者, 解析器)
使用整頁重新導向流程驗證 Firebase 用戶端。
如要處理這項作業的結果和錯誤,請參閱 getRedirectResult()。使用 signInWithRedirect() 時,請遵循最佳做法。
這個方法不適用於 Node.js 環境,或是以 FirebaseServerApp 建立的 Auth 執行個體。
簽名:
export declare function signInWithRedirect(auth: Auth, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<never>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
提供者 | AuthProvider | 要驗證的供應商。提供者必須是 OAuthProvider。EmailAuthProvider 等非 OAuth 供應商則會擲回錯誤。 |
解析器 | PopupRedirectResolver | PopupRedirectResolver 的執行個體,如果已提供至 initializeAuth() 或由 getAuth() 提供,則為選用。 |
傳回:
Promise<never>
範例
// Sign in using a redirect.
const provider = new FacebookAuthProvider();
// You can add additional scopes to the provider:
provider.addScope('user_birthday');
// Start a sign in process for an unauthenticated user.
await signInWithRedirect(auth, provider);
// This will trigger a full page redirect away from your app
// After returning from the redirect when your app initializes you can obtain the result
const result = await getRedirectResult(auth);
if (result) {
// This is the signed-in user
const user = result.user;
// This gives you a Facebook Access Token.
const credential = provider.credentialFromResult(auth, result);
const token = credential.accessToken;
}
// As this API can be used for sign-in, linking and reauthentication,
// check the operationType to determine what triggered this redirect
// operation.
const operationType = result.operationType;
signOut(auth)
登出目前的使用者。
使用 FirebaseServerApp 建立的 Auth 執行個體不支援這個方法。
簽名:
export declare function signOut(auth: Auth): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
傳回:
承諾<void>
updateCurrentUser(auth, 使用者)
在 Auth 執行個體上,以非同步方式將您提供的使用者設為 Auth.currentUser。
將建立使用者的新執行個體副本,並將其設定為 currentUser。
這會觸發 onAuthStateChanged() 和 onIdTokenChanged() 監聽器,就像其他登入方法一樣。
如果要更新的使用者屬於其他 Firebase 專案,作業就會失敗。
使用 FirebaseServerApp 建立的 Auth 執行個體不支援這個方法。
簽名:
export declare function updateCurrentUser(auth: Auth, user: User | null): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
使用者 | 使用者 | 空值 | 新的使用者。 |
傳回:
承諾<void>
useDeviceLanguage(auth)
將目前的語言設為預設的裝置/瀏覽器偏好設定。
簽名:
export declare function useDeviceLanguage(auth: Auth): void;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
傳回:
無效
VerifyPassword(驗證, 密碼)
根據為專案或用戶群設定的密碼政策驗證密碼。
如未在 Auth
執行個體上設定用戶群 ID,則這個方法會使用為專案設定的密碼政策。否則,這個方法會使用為用戶群設定的政策。如未設定密碼政策,系統會使用您為所有專案設定的預設政策。
如果因提交的密碼不符合密碼政策規定而驗證流程失敗,而先前呼叫過這個方法,則這個方法會在再次呼叫時使用最新可用的政策。
簽名:
export declare function validatePassword(auth: Auth, password: string): Promise<PasswordValidationStatus>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
密碼 | 字串 | 要驗證的密碼。 |
傳回:
Promise<PasswordValidationStatus>
範例
validatePassword(auth, 'some-password');
VerifyPasswordResetCode(auth, code)
檢查透過電子郵件或其他頻外機制傳送給使用者的密碼重設碼。
簽名:
export declare function verifyPasswordResetCode(auth: Auth, code: string): Promise<string>;
參數
參數 | 類型 | 說明 |
---|---|---|
auth | 驗證 | Auth 執行個體。 |
程式碼 | 字串 | 傳送給使用者的驗證碼。 |
傳回:
Promise<string>
使用者的電子郵件地址 (如果有效)。
function(連結, ...)
parseActionCodeURL(連結)
剖析電子郵件動作連結字串,並在連結有效時傳回 ActionCodeURL,否則傳回空值。
簽名:
export declare function parseActionCodeURL(link: string): ActionCodeURL | null;
參數
參數 | 類型 | 說明 |
---|---|---|
連結 | 字串 |
傳回:
ActionCodeURL | 空值
function(使用者, ...)
deleteUser(使用者)
刪除使用者並登出。
簽名:
export declare function deleteUser(user: User): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
傳回:
承諾<void>
getIdToken(使用者, forceRefresh)
傳回用於向 Firebase 服務識別使用者的 JSON Web Token (JWT)。
如果目前的權杖尚未過期或不會在接下來 5 分鐘內過期,則傳回目前的權杖。否則,系統會重新整理權杖,然後傳回新權杖。
簽名:
export declare function getIdToken(user: User, forceRefresh?: boolean): Promise<string>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
強制重新整理 | 布林值 | 無論權杖到期時間為何,一律強制重新整理。 |
傳回:
Promise<string>
getIdTokenResult(使用者, forceRefresh)
傳回用於識別 Firebase 服務使用者的去序列化 JSON Web Token (JWT)。
如果目前的權杖尚未過期或不會在接下來 5 分鐘內過期,則傳回目前的權杖。否則,系統會重新整理權杖,然後傳回新權杖。
簽名:
export declare function getIdTokenResult(user: User, forceRefresh?: boolean): Promise<IdTokenResult>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
強制重新整理 | 布林值 | 無論權杖到期時間為何,一律強制重新整理。 |
傳回:
Promise<IdTokenResult>
linkWithCredential(使用者、憑證)
連結使用者帳戶與指定憑證。
AuthProvider 可用來產生憑證,
簽名:
export declare function linkWithCredential(user: User, credential: AuthCredential): Promise<UserCredential>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
憑證 | AuthCredential | 驗證憑證。 |
傳回:
Promise<使用者憑證>
linkWithPhoneNumber(使用者、電話號碼、appVerifier)
將使用者帳戶與指定的電話號碼連結。
這個方法不適用於 Node.js 環境。
簽名:
export declare function linkWithPhoneNumber(user: User, phoneNumber: string, appVerifier: ApplicationVerifier): Promise<ConfirmationResult>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
phoneNumber | 字串 | 使用者的電話號碼,格式為 E.164 (例如 +16505550101)。 |
應用程式驗證器 | ApplicationVerifier | ApplicationVerifier。 |
傳回:
Promise<ConfirmationResult>
linkWithPopup(使用者、提供者、解析器)
使用彈出式視窗的 OAuth 流程,將已驗證的供應商連結至使用者帳戶。
如果連結成功,傳回的結果會包含使用者和提供者的憑證。
這個方法不適用於 Node.js 環境。
簽名:
export declare function linkWithPopup(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<UserCredential>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
提供者 | AuthProvider | 要驗證的供應商。提供者必須是 OAuthProvider。EmailAuthProvider 等非 OAuth 供應商則會擲回錯誤。 |
解析器 | PopupRedirectResolver | PopupRedirectResolver 的執行個體,如果已提供至 initializeAuth() 或由 getAuth() 提供,則為選用。 |
傳回:
Promise<使用者憑證>
範例
// Sign in using some other provider.
const result = await signInWithEmailAndPassword(auth, email, password);
// Link using a popup.
const provider = new FacebookAuthProvider();
await linkWithPopup(result.user, provider);
linkWithRedirect(使用者、供應商、解析器)
使用整頁重新導向流程,將 OAuthProvider 連結至使用者帳戶。
如要處理這項作業的結果和錯誤,請參閱 getRedirectResult()。使用 linkWithRedirect() 時,請遵循最佳做法。
這個方法不適用於 Node.js 環境,或是以 FirebaseServerApp 建立的 Auth 執行個體。
簽名:
export declare function linkWithRedirect(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<never>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
提供者 | AuthProvider | 要驗證的供應商。提供者必須是 OAuthProvider。EmailAuthProvider 等非 OAuth 供應商則會擲回錯誤。 |
解析器 | PopupRedirectResolver | PopupRedirectResolver 的執行個體,如果已提供至 initializeAuth() 或由 getAuth() 提供,則為選用。 |
傳回:
Promise<never>
範例
// Sign in using some other provider.
const result = await signInWithEmailAndPassword(auth, email, password);
// Link using a redirect.
const provider = new FacebookAuthProvider();
await linkWithRedirect(result.user, provider);
// This will trigger a full page redirect away from your app
// After returning from the redirect when your app initializes you can obtain the result
const result = await getRedirectResult(auth);
多因素(使用者)
與使用者對應的 MultiFactorUser。
用於存取與使用者相關的所有多重要素屬性和作業。
簽名:
export declare function multiFactor(user: User): MultiFactorUser;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
傳回:
reauthenticateWithCredential(使用者、憑證)
使用新憑證重新驗證使用者。
如果在執行操作前,需要執行 updatePassword() 等作業,那麼才能執行近期登入嘗試中的權杖。使用這個方法可以復原 CREDENTIAL_TOO_OLD_LOGIN_AGAIN
錯誤或 TOKEN_EXPIRED
錯誤。
任何由使用 FirebaseServerApp 建立的 Auth 執行個體登入的 User 都不支援這個方法。
簽名:
export declare function reauthenticateWithCredential(user: User, credential: AuthCredential): Promise<UserCredential>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
憑證 | AuthCredential | 驗證憑證。 |
傳回:
Promise<使用者憑證>
reauthenticateWithPhoneNumber(使用者、電話號碼、appVerifier)
使用全新手機憑證重新驗證使用者。
如果在執行操作前,需要執行 updatePassword() 等作業,那麼才能執行近期登入嘗試中的權杖。
這個方法不適用於 Node.js 環境,或是任何由使用 FirebaseServerApp 建立的 Auth 執行個體所登入的 User。
簽名:
export declare function reauthenticateWithPhoneNumber(user: User, phoneNumber: string, appVerifier: ApplicationVerifier): Promise<ConfirmationResult>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
phoneNumber | 字串 | 使用者的電話號碼,格式為 E.164 (例如 +16505550101)。 |
應用程式驗證器 | ApplicationVerifier | ApplicationVerifier。 |
傳回:
Promise<ConfirmationResult>
reauthenticateWithPopup(使用者、提供者、解析器)
使用彈出式視窗的 OAuth 流程,以指定的 OAuthProvider 重新驗證目前的使用者。
如果重新驗證成功,傳回的結果會包含使用者和提供者的憑證。
這個方法不適用於 Node.js 環境,或是任何由使用 FirebaseServerApp 建立的 Auth 執行個體所登入的 User。
簽名:
export declare function reauthenticateWithPopup(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<UserCredential>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
提供者 | AuthProvider | 要驗證的供應商。提供者必須是 OAuthProvider。EmailAuthProvider 等非 OAuth 供應商則會擲回錯誤。 |
解析器 | PopupRedirectResolver | PopupRedirectResolver 的執行個體,如果已提供至 initializeAuth() 或由 getAuth() 提供,則為選用。 |
傳回:
Promise<使用者憑證>
範例
// Sign in using a popup.
const provider = new FacebookAuthProvider();
const result = await signInWithPopup(auth, provider);
// Reauthenticate using a popup.
await reauthenticateWithPopup(result.user, provider);
reauthenticateWithRedirect(使用者、供應商、解析器)
使用整頁重新導向流程,透過指定的 OAuthProvider 重新驗證目前的使用者。
如要處理這項作業的結果和錯誤,請參閱 getRedirectResult()。使用 reauthenticateWithRedirect() 時,請遵循最佳做法。
這個方法不適用於 Node.js 環境,或是以 FirebaseServerApp 建立的 Auth 執行個體。
簽名:
export declare function reauthenticateWithRedirect(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<never>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
提供者 | AuthProvider | 要驗證的供應商。提供者必須是 OAuthProvider。EmailAuthProvider 等非 OAuth 供應商則會擲回錯誤。 |
解析器 | PopupRedirectResolver | PopupRedirectResolver 的執行個體,如果已提供至 initializeAuth() 或由 getAuth() 提供,則為選用。 |
傳回:
Promise<never>
範例
// Sign in using a redirect.
const provider = new FacebookAuthProvider();
const result = await signInWithRedirect(auth, provider);
// This will trigger a full page redirect away from your app
// After returning from the redirect when your app initializes you can obtain the result
const result = await getRedirectResult(auth);
// Reauthenticate using a redirect.
await reauthenticateWithRedirect(result.user, provider);
// This will again trigger a full page redirect away from your app
// After returning from the redirect when your app initializes you can obtain the result
const result = await getRedirectResult(auth);
重新載入(使用者)
重新載入使用者帳戶資料 (如果已登入)。
簽名:
export declare function reload(user: User): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
傳回:
承諾<void>
sendEmailVerification(使用者, actionCodeSettings)
傳送驗證電子郵件給使用者。
藉由呼叫 applyActionCode() 完成驗證程序。
簽名:
export declare function sendEmailVerification(user: User, actionCodeSettings?: ActionCodeSettings | null): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
actionCodeSettings | ActionCodeSettings | 空值 | ActionCodeSettings。 |
傳回:
承諾<void>
範例
const actionCodeSettings = {
url: 'https://www.example.com/?email=user@example.com',
iOS: {
bundleId: 'com.example.ios'
},
android: {
packageName: 'com.example.android',
installApp: true,
minimumVersion: '12'
},
handleCodeInApp: true
};
await sendEmailVerification(user, actionCodeSettings);
// Obtain code from the user.
await applyActionCode(auth, code);
取消連結(使用者, 供應商 ID)
取消提供者與使用者帳戶的連結。
簽名:
export declare function unlink(user: User, providerId: string): Promise<User>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
供應商 ID | 字串 | 要取消連結的供應商。 |
傳回:
Promise<使用者>
updateEmail(使用者, 新電子郵件)
更新使用者的電子郵件地址。
系統會發送電子郵件至原電子郵件地址 (如果已設定的話),允許撤銷電子郵件地址變更,避免帳戶遭到盜用。
任何由使用 FirebaseServerApp 建立的 Auth 執行個體登入的 User 都不支援這個方法。
簽名:
export declare function updateEmail(user: User, newEmail: string): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
新電子郵件 | 字串 | 新電子郵件地址。啟用電子郵件 Enumeration Protection 時,會出現「auth/operation-not-allowed」錯誤。已淘汰,請改用 verifyBeforeUpdateEmail()。 |
傳回:
承諾<void>
updatePassword(使用者, newPassword)
更新使用者的密碼。
簽名:
export declare function updatePassword(user: User, newPassword: string): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
新密碼 | 字串 | 新密碼。 |
傳回:
承諾<void>
updatePhoneNumber(使用者, 憑證)
更新使用者的電話號碼。
這個方法不適用於 Node.js 環境,或是任何由使用 FirebaseServerApp 建立的 Auth 執行個體所登入的 User。
簽名:
export declare function updatePhoneNumber(user: User, credential: PhoneAuthCredential): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
憑證 | PhoneAuthCredential | 驗證新電話號碼的憑證。 |
傳回:
承諾<void>
範例
// 'recaptcha-container' is the ID of an element in the DOM.
const applicationVerifier = new RecaptchaVerifier('recaptcha-container');
const provider = new PhoneAuthProvider(auth);
const verificationId = await provider.verifyPhoneNumber('+16505550101', applicationVerifier);
// Obtain the verificationCode from the user.
const phoneCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
await updatePhoneNumber(user, phoneCredential);
updateProfile(user, { displayName, photosURL: photosUrl })
更新使用者的個人資料。
簽名:
export declare function updateProfile(user: User, { displayName, photoURL: photoUrl }: {
displayName?: string | null;
photoURL?: string | null;
}): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
{ displayName, photosURL:photoUrl } | { displayName?: string | null; photosURL?: 字串 | null; } |
傳回:
承諾<void>
VerifyBeforeUpdateEmail(使用者, newEmail, actionCodeSettings)
傳送驗證電子郵件到新的電子郵件地址。
使用者的電子郵件地址會在通過驗證後更新為新電子郵件地址。
如果您有自訂電子郵件動作處理常式,請呼叫 applyActionCode() 完成驗證程序。
簽名:
export declare function verifyBeforeUpdateEmail(user: User, newEmail: string, actionCodeSettings?: ActionCodeSettings | null): Promise<void>;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者 | User | 使用者。 |
新電子郵件 | 字串 | 要先驗證新的電子郵件地址,才能進行更新。 |
actionCodeSettings | ActionCodeSettings | 空值 | ActionCodeSettings。 |
傳回:
承諾<void>
範例
const actionCodeSettings = {
url: 'https://www.example.com/?email=user@example.com',
iOS: {
bundleId: 'com.example.ios'
},
android: {
packageName: 'com.example.android',
installApp: true,
minimumVersion: '12'
},
handleCodeInApp: true
};
await verifyBeforeUpdateEmail(user, 'newemail@example.com', actionCodeSettings);
// Obtain code from the user.
await applyActionCode(auth, code);
function(使用者憑證, ...)
getAdditionalUserInfo(使用者憑證)
擷取指定憑證的供應商特定 AdditionalUserInfo。
簽名:
export declare function getAdditionalUserInfo(userCredential: UserCredential): AdditionalUserInfo | null;
參數
參數 | 類型 | 說明 |
---|---|---|
使用者憑證 | 使用者憑證 | 使用者憑證。 |
傳回:
AdditionalUserInfo | 空值
ActionCodeOperation
可能的電子郵件動作型別列舉。
簽名:
ActionCodeOperation: {
readonly EMAIL_SIGNIN: "EMAIL_SIGNIN";
readonly PASSWORD_RESET: "PASSWORD_RESET";
readonly RECOVER_EMAIL: "RECOVER_EMAIL";
readonly REVERT_SECOND_FACTOR_ADDITION: "REVERT_SECOND_FACTOR_ADDITION";
readonly VERIFY_AND_CHANGE_EMAIL: "VERIFY_AND_CHANGE_EMAIL";
readonly VERIFY_EMAIL: "VERIFY_EMAIL";
}
AuthErrorCodes
潛在 Auth
錯誤代碼的對應,方便比較 SDK 擲回的錯誤。
請注意,地圖中的個別鍵並不能搖晃,因此使用地圖可能會大幅增加套件大小。
簽名:
AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY: {
readonly ADMIN_ONLY_OPERATION: "auth/admin-restricted-operation";
readonly ARGUMENT_ERROR: "auth/argument-error";
readonly APP_NOT_AUTHORIZED: "auth/app-not-authorized";
readonly APP_NOT_INSTALLED: "auth/app-not-installed";
readonly CAPTCHA_CHECK_FAILED: "auth/captcha-check-failed";
readonly CODE_EXPIRED: "auth/code-expired";
readonly CORDOVA_NOT_READY: "auth/cordova-not-ready";
readonly CORS_UNSUPPORTED: "auth/cors-unsupported";
readonly CREDENTIAL_ALREADY_IN_USE: "auth/credential-already-in-use";
readonly CREDENTIAL_MISMATCH: "auth/custom-token-mismatch";
readonly CREDENTIAL_TOO_OLD_LOGIN_AGAIN: "auth/requires-recent-login";
readonly DEPENDENT_SDK_INIT_BEFORE_AUTH: "auth/dependent-sdk-initialized-before-auth";
readonly DYNAMIC_LINK_NOT_ACTIVATED: "auth/dynamic-link-not-activated";
readonly EMAIL_CHANGE_NEEDS_VERIFICATION: "auth/email-change-needs-verification";
readonly EMAIL_EXISTS: "auth/email-already-in-use";
readonly EMULATOR_CONFIG_FAILED: "auth/emulator-config-failed";
readonly EXPIRED_OOB_CODE: "auth/expired-action-code";
readonly EXPIRED_POPUP_REQUEST: "auth/cancelled-popup-request";
readonly INTERNAL_ERROR: "auth/internal-error";
readonly INVALID_API_KEY: "auth/invalid-api-key";
readonly INVALID_APP_CREDENTIAL: "auth/invalid-app-credential";
readonly INVALID_APP_ID: "auth/invalid-app-id";
readonly INVALID_AUTH: "auth/invalid-user-token";
readonly INVALID_AUTH_EVENT: "auth/invalid-auth-event";
readonly INVALID_CERT_HASH: "auth/invalid-cert-hash";
readonly INVALID_CODE: "auth/invalid-verification-code";
readonly INVALID_CONTINUE_URI: "auth/invalid-continue-uri";
readonly INVALID_CORDOVA_CONFIGURATION: "auth/invalid-cordova-configuration";
readonly INVALID_CUSTOM_TOKEN: "auth/invalid-custom-token";
readonly INVALID_DYNAMIC_LINK_DOMAIN: "auth/invalid-dynamic-link-domain";
readonly INVALID_EMAIL: "auth/invalid-email";
readonly INVALID_EMULATOR_SCHEME: "auth/invalid-emulator-scheme";
readonly INVALID_IDP_RESPONSE: "auth/invalid-credential";
readonly INVALID_LOGIN_CREDENTIALS: "auth/invalid-credential";
readonly INVALID_MESSAGE_PAYLOAD: "auth/invalid-message-payload";
readonly INVALID_MFA_SESSION: "auth/invalid-multi-factor-session";
readonly INVALID_OAUTH_CLIENT_ID: "auth/invalid-oauth-client-id";
readonly INVALID_OAUTH_PROVIDER: "auth/invalid-oauth-provider";
readonly INVALID_OOB_CODE: "auth/invalid-action-code";
readonly INVALID_ORIGIN: "auth/unauthorized-domain";
readonly INVALID_PASSWORD: "auth/wrong-password";
readonly INVALID_PERSISTENCE: "auth/invalid-persistence-type";
readonly INVALID_PHONE_NUMBER: "auth/invalid-phone-number";
readonly INVALID_PROVIDER_ID: "auth/invalid-provider-id";
readonly INVALID_RECIPIENT_EMAIL: "auth/invalid-recipient-email";
readonly INVALID_SENDER: "auth/invalid-sender";
readonly INVALID_SESSION_INFO: "auth/invalid-verification-id";
readonly INVALID_TENANT_ID: "auth/invalid-tenant-id";
readonly MFA_INFO_NOT_FOUND: "auth/multi-factor-info-not-found";
readonly MFA_REQUIRED: "auth/multi-factor-auth-required";
readonly MISSING_ANDROID_PACKAGE_NAME: "auth/missing-android-pkg-name";
readonly MISSING_APP_CREDENTIAL: "auth/missing-app-credential";
readonly MISSING_AUTH_DOMAIN: "auth/auth-domain-config-required";
readonly MISSING_CODE: "auth/missing-verification-code";
readonly MISSING_CONTINUE_URI: "auth/missing-continue-uri";
readonly MISSING_IFRAME_START: "auth/missing-iframe-start";
readonly MISSING_IOS_BUNDLE_ID: "auth/missing-ios-bundle-id";
readonly MISSING_OR_INVALID_NONCE: "auth/missing-or-invalid-nonce";
readonly MISSING_MFA_INFO: "auth/missing-multi-factor-info";
readonly MISSING_MFA_SESSION: "auth/missing-multi-factor-session";
readonly MISSING_PHONE_NUMBER: "auth/missing-phone-number";
readonly MISSING_SESSION_INFO: "auth/missing-verification-id";
readonly MODULE_DESTROYED: "auth/app-deleted";
readonly NEED_CONFIRMATION: "auth/account-exists-with-different-credential";
readonly NETWORK_REQUEST_FAILED: "auth/network-request-failed";
readonly NULL_USER: "auth/null-user";
readonly NO_AUTH_EVENT: "auth/no-auth-event";
readonly NO_SUCH_PROVIDER: "auth/no-such-provider";
readonly OPERATION_NOT_ALLOWED: "auth/operation-not-allowed";
readonly OPERATION_NOT_SUPPORTED: "auth/operation-not-supported-in-this-environment";
readonly POPUP_BLOCKED: "auth/popup-blocked";
readonly POPUP_CLOSED_BY_USER: "auth/popup-closed-by-user";
readonly PROVIDER_ALREADY_LINKED: "auth/provider-already-linked";
readonly QUOTA_EXCEEDED: "auth/quota-exceeded";
readonly REDIRECT_CANCELLED_BY_USER: "auth/redirect-cancelled-by-user";
readonly REDIRECT_OPERATION_PENDING: "auth/redirect-operation-pending";
readonly REJECTED_CREDENTIAL: "auth/rejected-credential";
readonly SECOND_FACTOR_ALREADY_ENROLLED: "auth/second-factor-already-in-use";
readonly SECOND_FACTOR_LIMIT_EXCEEDED: "auth/maximum-second-factor-count-exceeded";
readonly TENANT_ID_MISMATCH: "auth/tenant-id-mismatch";
readonly TIMEOUT: "auth/timeout";
readonly TOKEN_EXPIRED: "auth/user-token-expired";
readonly TOO_MANY_ATTEMPTS_TRY_LATER: "auth/too-many-requests";
readonly UNAUTHORIZED_DOMAIN: "auth/unauthorized-continue-uri";
readonly UNSUPPORTED_FIRST_FACTOR: "auth/unsupported-first-factor";
readonly UNSUPPORTED_PERSISTENCE: "auth/unsupported-persistence-type";
readonly UNSUPPORTED_TENANT_OPERATION: "auth/unsupported-tenant-operation";
readonly UNVERIFIED_EMAIL: "auth/unverified-email";
readonly USER_CANCELLED: "auth/user-cancelled";
readonly USER_DELETED: "auth/user-not-found";
readonly USER_DISABLED: "auth/user-disabled";
readonly USER_MISMATCH: "auth/user-mismatch";
readonly USER_SIGNED_OUT: "auth/user-signed-out";
readonly WEAK_PASSWORD: "auth/weak-password";
readonly WEB_STORAGE_UNSUPPORTED: "auth/web-storage-unsupported";
readonly ALREADY_INITIALIZED: "auth/already-initialized";
readonly RECAPTCHA_NOT_ENABLED: "auth/recaptcha-not-enabled";
readonly MISSING_RECAPTCHA_TOKEN: "auth/missing-recaptcha-token";
readonly INVALID_RECAPTCHA_TOKEN: "auth/invalid-recaptcha-token";
readonly INVALID_RECAPTCHA_ACTION: "auth/invalid-recaptcha-action";
readonly MISSING_CLIENT_TYPE: "auth/missing-client-type";
readonly MISSING_RECAPTCHA_VERSION: "auth/missing-recaptcha-version";
readonly INVALID_RECAPTCHA_VERSION: "auth/invalid-recaptcha-version";
readonly INVALID_REQ_TYPE: "auth/invalid-req-type";
}
瀏覽器本機永久
使用 localStorage
做為基礎儲存空間,實作 LOCAL
類型的持續性實作。
簽名:
browserLocalPersistence: Persistence
BrowserPopupRedirectResolver
適用於瀏覽器應用程式的 PopupRedirectResolver 實作。
這個方法不適用於 Node.js 環境。
簽名:
browserPopupRedirectResolver: PopupRedirectResolver
瀏覽器工作階段持續性
使用 sessionStorage
做為基礎儲存空間的 SESSION
持續性實作。
簽名:
browserSessionPersistence: Persistence
cordovaPopupRedirectResolver
適用於 Cordova 型應用程式的 PopupRedirectResolver 實作。
簽名:
cordovaPopupRedirectResolver: PopupRedirectResolver
偵錯錯誤地圖
詳細的錯誤地圖,其中提供多數錯誤代碼的詳細說明。
請參閱 AuthErrorMap 的討論
簽名:
debugErrorMap: AuthErrorMap
因素 ID
可用於多重驗證的因素列舉。
簽名:
FactorId: {
readonly PHONE: "phone";
readonly TOTP: "totp";
}
已建立索引的資料庫本機永久性
使用 indexedDB
做為基礎儲存空間,實作 LOCAL
類型的持續性實作。
簽名:
indexedDBLocalPersistence: Persistence
記憶體持續性
「NONE」類型的持續性實作。
簽名:
inMemoryPersistence: Persistence
OperationType
支援的作業類型的列舉。
簽名:
OperationType: {
readonly LINK: "link";
readonly REAUTHENTICATE: "reauthenticate";
readonly SIGN_IN: "signIn";
}
prodErrorMap
最小的錯誤地圖,其中已移除所有詳細錯誤訊息。
請參閱 AuthErrorMap 的討論
簽名:
prodErrorMap: AuthErrorMap
供應商 ID
支援提供者的列舉。
簽名:
ProviderId: {
readonly FACEBOOK: "facebook.com";
readonly GITHUB: "github.com";
readonly GOOGLE: "google.com";
readonly PASSWORD: "password";
readonly PHONE: "phone";
readonly TWITTER: "twitter.com";
}
登入方法
支援的登入方法列舉。
簽名:
SignInMethod: {
readonly EMAIL_LINK: "emailLink";
readonly EMAIL_PASSWORD: "password";
readonly FACEBOOK: "facebook.com";
readonly GITHUB: "github.com";
readonly GOOGLE: "google.com";
readonly PHONE: "phone";
readonly TWITTER: "twitter.com";
}
自訂參數
OAuth 自訂參數對應。
簽名:
export declare type CustomParameters = Record<string, string>;
NextOrObserver
事件回呼的類型定義。
簽名:
export declare type NextOrObserver<T> = NextFn<T | null> | Observer<T | null>;
手機資訊選項
驗證電話號碼擁有權所需的資訊。
您需要提供的資訊,取決於您的登入方式是單因素登入、多重要素註冊還是多重登入。
簽名:
export declare type PhoneInfoOptions = PhoneSingleFactorInfoOptions | PhoneMultiFactorEnrollInfoOptions | PhoneMultiFactorSignInInfoOptions;
使用者個人檔案
AdditionalUserInfo 中使用的使用者個人資料。
簽名:
export declare type UserProfile = Record<string, unknown>;