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

Commit

Permalink
Merge pull request #12 from clerkinc/post-clean-up
Browse files Browse the repository at this point in the history
Adding Sign Up component
  • Loading branch information
perkinsjr authored Dec 27, 2022
2 parents 60652ae + 2d76d65 commit 8a2fff3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
4 changes: 2 additions & 2 deletions apps/expo/src/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -23,7 +23,7 @@ export const App = () => {
</TRPCProvider>
</SignedIn>
<SignedOut>
<SignInScreen />
<SignInSignUpScreen />
</SignedOut>
</ClerkProvider>
);
Expand Down
72 changes: 72 additions & 0 deletions apps/expo/src/components/SignUpWithOAuth.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<View className="my-8 rounded-lg border-2 border-gray-500 p-4">
<Button
title="Sign Up with Discord"
onPress={handleSignUpWithDiscordPress}
/>
</View>
);
};

export default SignUpWithOAuth;
4 changes: 3 additions & 1 deletion apps/expo/src/screens/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import React from "react";
import { View, SafeAreaView } from "react-native";

import SignInWithOAuth from "../components/SignInWithOAuth";
import SignUpWithOAuth from "../components/SignUpWithOAuth";

export const SignInScreen = () => {
export const SignInSignUpScreen = () => {
return (
<SafeAreaView className="bg-[#2e026d] bg-gradient-to-b from-[#2e026d] to-[#15162c]">
<View className="h-full w-full p-4">
<SignUpWithOAuth />
<SignInWithOAuth />
</View>
</SafeAreaView>
Expand Down

0 comments on commit 8a2fff3

Please sign in to comment.