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 #19 from clerkinc/sign-up-transfer
Browse files Browse the repository at this point in the history
Create an account instead of requiring the user to resign in
  • Loading branch information
perkinsjr authored Jan 13, 2023
2 parents 03c16b9 + 91df357 commit 264589d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 77 deletions.
23 changes: 20 additions & 3 deletions apps/expo/src/components/SignInWithOAuth.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useSignIn } from "@clerk/clerk-expo";
import { useSignUp, useSignIn } from "@clerk/clerk-expo";
import React from "react";
import { Button, View } from "react-native";

import * as AuthSession from "expo-auth-session";

const SignInWithOAuth = () => {
const { isLoaded, signIn, setSession } = useSignIn();

const { signUp } = useSignUp();
if (!isLoaded) return null;

const handleSignInWithDiscordPress = async () => {
Expand All @@ -32,7 +32,7 @@ const SignInWithOAuth = () => {
// 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.";
}
Expand All @@ -45,6 +45,23 @@ const SignInWithOAuth = () => {
const { createdSessionId } = signIn;

if (!createdSessionId) {
if (signIn.firstFactorVerification.status === "transferable") {
console.log("Didn't have an account transferring");

await signUp.create({ transfer: true });

const { rotating_token_nonce: rotatingTokenNonce } = params;

await signUp.reload({ rotatingTokenNonce });

const { createdSessionId } = signUp;
if (!createdSessionId) {
throw "Something went wrong during the Sign up OAuth flow. Please ensure that all sign up requirements are met.";
}
await setSession(createdSessionId);

return;
}
throw "Something went wrong during the Sign in OAuth flow. Please ensure that all sign in requirements are met.";
}

Expand Down
72 changes: 0 additions & 72 deletions apps/expo/src/components/SignUpWithOAuth.tsx

This file was deleted.

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

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

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 264589d

Please sign in to comment.