Home > @firebase/auth > signInWithRedirect
signInWithRedirect() function
Authenticates a Firebase client using a full-page redirect flow.
Signature:
export declare function signInWithRedirect(auth: Auth, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<never>;
Parameters
Parameter | Type | Description |
---|---|---|
auth | Auth | The Auth instance. |
provider | AuthProvider | The provider to authenticate. The provider has to be an OAuthProvider. Non-OAuth providers like EmailAuthProvider will throw an error. |
resolver | PopupRedirectResolver | An instance of PopupRedirectResolver, optional if already supplied to initializeAuth() or provided by getAuth(). |
Returns:
Promise<never>
Description
To handle the results and errors for this operation, refer to getRedirectResult().
Example
// 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;