diff --git a/apps/expo/src/_app.tsx b/apps/expo/src/_app.tsx index 78603ca..00e4c85 100644 --- a/apps/expo/src/_app.tsx +++ b/apps/expo/src/_app.tsx @@ -4,7 +4,7 @@ import { SafeAreaProvider } from "react-native-safe-area-context"; import { TRPCProvider } from "./utils/trpc"; import { HomeScreen } from "./screens/home"; -import { SignInScreen } from "./screens/signin"; +import { SignInSignUpScreen } from "./screens/signin"; import { ClerkProvider, SignedIn, SignedOut } from "@clerk/clerk-expo"; import { tokenCache } from "./utils/cache"; @@ -23,7 +23,7 @@ export const App = () => { - + ); diff --git a/apps/expo/src/components/SignUpWithOAuth.tsx b/apps/expo/src/components/SignUpWithOAuth.tsx new file mode 100644 index 0000000..7acfca0 --- /dev/null +++ b/apps/expo/src/components/SignUpWithOAuth.tsx @@ -0,0 +1,72 @@ +import { useSignUp } from "@clerk/clerk-expo"; +import React from "react"; +import { Button, View } from "react-native"; + +import * as AuthSession from "expo-auth-session"; + +const SignUpWithOAuth = () => { + const { isLoaded, signUp, setSession } = useSignUp(); + + if (!isLoaded) return null; + + const handleSignUpWithDiscordPress = async () => { + try { + const redirectUrl = AuthSession.makeRedirectUri({ + path: "/oauth-native-callback", + }); + + await signUp.create({ + strategy: "oauth_discord", + redirectUrl, + }); + + const { + verifications: { + externalAccount: { externalVerificationRedirectURL }, + }, + } = signUp; + + const result = await AuthSession.startAsync({ + authUrl: externalVerificationRedirectURL!.toString(), + returnUrl: redirectUrl, + }); + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const { type, params } = result || {}; + console.log; + if (type !== "success") { + throw "Something went wrong during the OAuth flow. Try again."; + } + + // Get the rotatingTokenNonce from the redirect URL parameters + const { rotating_token_nonce: rotatingTokenNonce } = params; + + await signUp.reload({ rotatingTokenNonce }); + + const { createdSessionId } = signUp; + + if (!createdSessionId) { + throw "Something went wrong during the Sign in OAuth flow. Please ensure that all sign in requirements are met."; + } + + await setSession(createdSessionId); + + return; + } catch (err) { + console.log(JSON.stringify(err, null, 2)); + console.log("error signing in", err); + } + }; + + return ( + +