Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 8a2fff3

Browse files
authored
Merge pull request #12 from clerkinc/post-clean-up
Adding Sign Up component
2 parents 60652ae + 2d76d65 commit 8a2fff3

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

apps/expo/src/_app.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SafeAreaProvider } from "react-native-safe-area-context";
44
import { TRPCProvider } from "./utils/trpc";
55

66
import { HomeScreen } from "./screens/home";
7-
import { SignInScreen } from "./screens/signin";
7+
import { SignInSignUpScreen } from "./screens/signin";
88
import { ClerkProvider, SignedIn, SignedOut } from "@clerk/clerk-expo";
99
import { tokenCache } from "./utils/cache";
1010

@@ -23,7 +23,7 @@ export const App = () => {
2323
</TRPCProvider>
2424
</SignedIn>
2525
<SignedOut>
26-
<SignInScreen />
26+
<SignInSignUpScreen />
2727
</SignedOut>
2828
</ClerkProvider>
2929
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { useSignUp } from "@clerk/clerk-expo";
2+
import React from "react";
3+
import { Button, View } from "react-native";
4+
5+
import * as AuthSession from "expo-auth-session";
6+
7+
const SignUpWithOAuth = () => {
8+
const { isLoaded, signUp, setSession } = useSignUp();
9+
10+
if (!isLoaded) return null;
11+
12+
const handleSignUpWithDiscordPress = async () => {
13+
try {
14+
const redirectUrl = AuthSession.makeRedirectUri({
15+
path: "/oauth-native-callback",
16+
});
17+
18+
await signUp.create({
19+
strategy: "oauth_discord",
20+
redirectUrl,
21+
});
22+
23+
const {
24+
verifications: {
25+
externalAccount: { externalVerificationRedirectURL },
26+
},
27+
} = signUp;
28+
29+
const result = await AuthSession.startAsync({
30+
authUrl: externalVerificationRedirectURL!.toString(),
31+
returnUrl: redirectUrl,
32+
});
33+
34+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
35+
// @ts-ignore
36+
const { type, params } = result || {};
37+
console.log;
38+
if (type !== "success") {
39+
throw "Something went wrong during the OAuth flow. Try again.";
40+
}
41+
42+
// Get the rotatingTokenNonce from the redirect URL parameters
43+
const { rotating_token_nonce: rotatingTokenNonce } = params;
44+
45+
await signUp.reload({ rotatingTokenNonce });
46+
47+
const { createdSessionId } = signUp;
48+
49+
if (!createdSessionId) {
50+
throw "Something went wrong during the Sign in OAuth flow. Please ensure that all sign in requirements are met.";
51+
}
52+
53+
await setSession(createdSessionId);
54+
55+
return;
56+
} catch (err) {
57+
console.log(JSON.stringify(err, null, 2));
58+
console.log("error signing in", err);
59+
}
60+
};
61+
62+
return (
63+
<View className="my-8 rounded-lg border-2 border-gray-500 p-4">
64+
<Button
65+
title="Sign Up with Discord"
66+
onPress={handleSignUpWithDiscordPress}
67+
/>
68+
</View>
69+
);
70+
};
71+
72+
export default SignUpWithOAuth;

apps/expo/src/screens/signin.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import React from "react";
33
import { View, SafeAreaView } from "react-native";
44

55
import SignInWithOAuth from "../components/SignInWithOAuth";
6+
import SignUpWithOAuth from "../components/SignUpWithOAuth";
67

7-
export const SignInScreen = () => {
8+
export const SignInSignUpScreen = () => {
89
return (
910
<SafeAreaView className="bg-[#2e026d] bg-gradient-to-b from-[#2e026d] to-[#15162c]">
1011
<View className="h-full w-full p-4">
12+
<SignUpWithOAuth />
1113
<SignInWithOAuth />
1214
</View>
1315
</SafeAreaView>

0 commit comments

Comments
 (0)