clerk sign in and sign up login setup

This commit is contained in:
Sanidhya Kumar Verma
2024-08-29 16:08:12 +00:00
committed by GitHub
parent 640961eeec
commit a5cabfe1a1
7 changed files with 139 additions and 11 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ const SignIn = () => {
className="mt-6"
/>
<OAuth />
<OAuth title="Sign in with Google" />
<Link
href="/sign-up"
+64 -2
View File
@@ -1,3 +1,4 @@
import { useSignUp } from "@clerk/clerk-expo";
import { Link } from "expo-router";
import { useState } from "react";
import { Image, ScrollView, Text, View } from "react-native";
@@ -8,13 +9,74 @@ import { OAuth } from "@/components/oauth";
import { icons, images } from "@/constants";
const SignUp = () => {
const { isLoaded, signUp, setActive } = useSignUp();
const [form, setForm] = useState({
name: "",
email: "",
password: "",
});
const onSignUpPress = async () => {};
const [verification, setVerification] = useState({
state: "default",
error: "",
code: "",
});
const onSignUpPress = async () => {
if (!isLoaded) return;
try {
await signUp.create({
emailAddress: form.email,
password: form.password,
firstName: form.name,
});
await signUp.prepareEmailAddressVerification({ strategy: "email_code" });
setVerification((prevVerification) => ({
...prevVerification,
state: "pending",
}));
} catch (err: any) {
console.error(JSON.stringify(err, null, 2));
}
};
const onPressVerify = async () => {
if (!isLoaded) return;
try {
const completeSignUp = await signUp.attemptEmailAddressVerification({
code: verification.code,
});
if (completeSignUp.status === "complete") {
// TODO: Create a database user
await setActive({ session: completeSignUp.createdSessionId });
setVerification((prevVerification) => ({
...prevVerification,
state: "success",
}));
} else {
setVerification((prevVerification) => ({
...prevVerification,
error: "Verification failed.",
state: "failed",
}));
console.error(JSON.stringify(completeSignUp, null, 2));
}
} catch (err: any) {
console.error(JSON.stringify(err, null, 2));
setVerification((prevVerification) => ({
...prevVerification,
error: err?.errors[0]?.longMessage,
state: "failed",
}));
}
};
return (
<ScrollView className="flex-1 bg-white">
@@ -79,7 +141,7 @@ const SignUp = () => {
className="mt-6"
/>
<OAuth />
<OAuth title="Sign up with Google" />
<Link
href="/sign-in"