Ovie
Ovie2mo ago

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
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;
}
3 Replies
Convex Bot
Convex Bot2mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart2mo ago
It will only skip the consent / account select screen after login if the user is only signed into one google account https://discord.com/channels/1019350475847499849/1363243870992859227/1363250690968916190 If they're logged into multiple it will show each time
Ye Aung
Ye Aung7d ago
Has this problem been resolved? I am also facing the problem. I already added prompt: "select_account" but the google account select screen is not show

Did you find this page helpful?