hasanaktasTR
hasanaktasTR6mo ago

Convex Auth - Capacitor Based web and mobile app

Can you prepare a document or example on how to log in on mobile for applications that use the Capacitor infrastructure? It works fine on the web side, but I couldn't run it on the mobile side. I think an intermediate layer is needed for Expo, such as the openAuthSessionAsync and makeRedirectUri functions used in the document.
5 Replies
Michal Srb
Michal Srb6mo ago
Hey! I assume you mean OAuth didn't work. How does it fail? It might be a while before we get to optimizing the library for Capacitor, but contributions are welcome!
hasanaktasTR
hasanaktasTROP6mo ago
I'm sorry for returning late. Streaming for web works fine as in video.
hasanaktasTR
hasanaktasTROP6mo ago
The same flow exits the application on the capacitor and opens the browser. I couldn't show it in the video, but the user is asking again and cannot redirect. It seems like we need to open the browser within the application, not externally. I think we need to use a library like @capacitor/browser (like expo-auth-session used for React native)
hasanaktasTR
hasanaktasTROP6mo ago
const { signIn } = useAuthActions();
const handleSignIn = async () => {
const { redirect } = await signIn("github", { redirectTo });
if (Platform.OS === "web") {
return;
}
const result = await openAuthSessionAsync(redirect!.toString(), redirectTo);
if (result.type === "success") {
const { url } = result;
const code = new URL(url).searchParams.get("code")!;
await signIn("github", { code });
}
};
const { signIn } = useAuthActions();
const handleSignIn = async () => {
const { redirect } = await signIn("github", { redirectTo });
if (Platform.OS === "web") {
return;
}
const result = await openAuthSessionAsync(redirect!.toString(), redirectTo);
if (result.type === "success") {
const { url } = result;
const code = new URL(url).searchParams.get("code")!;
await signIn("github", { code });
}
};
I could not find how to solve the flow in the code sample in a capacitor application.
Michal Srb
Michal Srb6mo ago
This might be more of a capacitor than Convex question.

Did you find this page helpful?