Configure Google OAuth to always present "select accounts" screen
Hey team.
Quick question. Is there a simple way to configure my Google OAuth setup to always require a user to select account. Currently, when I click the sign-in button, it just authenticates me with the last account I signed in with. I have multiple accounts.
My current code looks like this
Quick question. Is there a simple way to configure my Google OAuth setup to always require a user to select account. Currently, when I click the sign-in button, it just authenticates me with the last account I signed in with. I have multiple accounts.
My current code looks like this
if (provider !== "password") {
const { redirect } = await signIn(provider, {
redirectTo,
prompt: "select_account",
flow,
});
if (!redirect) {
throw new Error("Authentication redirect URL not found.");
}
const parsedRedirect = redirect!.toString();
const redirectWithParams = `${parsedRedirect}&prompt=login`;
const result = await openAuthSessionAsync(redirectWithParams, redirectTo);
if (result.type !== "success") {
throw new Error("Authentication failed. Please try again.");
}
const { url } = result;
const code = new URL(url).searchParams.get("code");
if (!code) {
throw new Error("Authentication code not found in the URL.");
}
const finalResult = await signIn(provider, { code });
if (!finalResult.signingIn) {
throw new Error("Authentication failed. Please try again.");
}
Toast.show({
type: "info",
text1: "Successful",
text2: flow === "signUp" ? "It's great to have you with us!" : "Welcome back!",
});
setTimeout(() => {
router.replace((params.redirectTo as Href) || "/(tabs)");
}, 1000);
return;
}if (provider !== "password") {
const { redirect } = await signIn(provider, {
redirectTo,
prompt: "select_account",
flow,
});
if (!redirect) {
throw new Error("Authentication redirect URL not found.");
}
const parsedRedirect = redirect!.toString();
const redirectWithParams = `${parsedRedirect}&prompt=login`;
const result = await openAuthSessionAsync(redirectWithParams, redirectTo);
if (result.type !== "success") {
throw new Error("Authentication failed. Please try again.");
}
const { url } = result;
const code = new URL(url).searchParams.get("code");
if (!code) {
throw new Error("Authentication code not found in the URL.");
}
const finalResult = await signIn(provider, { code });
if (!finalResult.signingIn) {
throw new Error("Authentication failed. Please try again.");
}
Toast.show({
type: "info",
text1: "Successful",
text2: flow === "signUp" ? "It's great to have you with us!" : "Welcome back!",
});
setTimeout(() => {
router.replace((params.redirectTo as Href) || "/(tabs)");
}, 1000);
return;
}