diff --git a/app/(tabs)/account/choose-full-name.tsx b/app/(tabs)/account/choose-full-name.tsx
index e8cff76..defca17 100644
--- a/app/(tabs)/account/choose-full-name.tsx
+++ b/app/(tabs)/account/choose-full-name.tsx
@@ -8,7 +8,7 @@ import { ERROR_MESSAGES } from "../../../utils/ErrorMessages";
export default function ChooseFullName() {
const styles = getStyles(useTheme());
- const { userId } = useLocalSearchParams();
+ const { userId, username, email, password } = useLocalSearchParams();
const [fullName, setFullName] = useState("");
const [errorMessage, setErrorMessage] = useState(" ");
@@ -27,7 +27,16 @@ export default function ChooseFullName() {
{errorMessage}
handleSubmitFullName(userId, fullName, setErrorMessage)}
+ onPress={() =>
+ handleSubmitFullName(
+ userId,
+ username,
+ fullName,
+ email,
+ password,
+ setErrorMessage,
+ )
+ }
style={styles.button}
>
@@ -40,7 +49,10 @@ export default function ChooseFullName() {
const handleSubmitFullName = async (
userId: string | string[],
+ username: string | string[],
fullName: string,
+ email: string | string[],
+ password: string | string[],
setErrorMessage: (message: string) => void,
) => {
try {
@@ -49,13 +61,22 @@ const handleSubmitFullName = async (
return;
}
+ const {
+ data: { session },
+ } = await supabase.auth.signUp({
+ email: email as string,
+ password: password as string,
+ });
+
const { error } = await supabase.from("profiles").upsert([
{
- id: userId,
+ id: session?.user.id,
updated_at: new Date(),
+ username: username,
full_name: fullName,
},
]);
+
if (error) {
throw error;
} else {
diff --git a/app/(tabs)/account/choose-username.tsx b/app/(tabs)/account/choose-username.tsx
index eb73688..084bb7a 100644
--- a/app/(tabs)/account/choose-username.tsx
+++ b/app/(tabs)/account/choose-username.tsx
@@ -2,13 +2,12 @@ import { router, useLocalSearchParams } from "expo-router";
import React, { useState } from "react";
import { StyleSheet, Text, TextInput, View } from "react-native";
import { Theme, useTheme } from "../../../utils/ThemeProvider";
-import { supabase } from "../../../utils/supabase";
import { TouchableOpacity } from "react-native-gesture-handler";
import { ERROR_MESSAGES } from "../../../utils/ErrorMessages";
export default function ChooseUsername() {
const styles = getStyles(useTheme());
- const { userId } = useLocalSearchParams();
+ const { userId, email, password } = useLocalSearchParams();
const [username, setUsername] = useState("");
const [errorMessage, setErrorMessage] = useState(" ");
@@ -27,7 +26,15 @@ export default function ChooseUsername() {
{errorMessage}
handleSubmitUsername(userId, username, setErrorMessage)}
+ onPress={() =>
+ handleSubmitUsername(
+ userId,
+ username,
+ email,
+ password,
+ setErrorMessage,
+ )
+ }
style={styles.button}
>
@@ -41,6 +48,8 @@ export default function ChooseUsername() {
const handleSubmitUsername = async (
userId: string | string[],
username: string,
+ email: string | string[],
+ password: string | string[],
setErrorMessage: (message: string) => void,
) => {
try {
@@ -49,19 +58,13 @@ const handleSubmitUsername = async (
return;
}
- const { error } = await supabase.from("profiles").upsert([
- {
- id: userId,
- updated_at: new Date(),
- username: username,
- },
- ]);
- if (error) {
- throw error;
- } else {
- router.push("/account/choose-full-name");
- router.setParams({ userId: userId });
- }
+ router.push("/account/choose-full-name");
+ router.setParams({
+ userId: userId,
+ username: username,
+ email: email,
+ password: password,
+ });
} catch (error) {
const typedError = error as { code: number };
setErrorMessage(ERROR_MESSAGES[typedError.code] || "Error saving");
diff --git a/components/auth.tsx b/components/auth.tsx
index ec75256..9d14139 100644
--- a/components/auth.tsx
+++ b/components/auth.tsx
@@ -32,24 +32,18 @@ export default function Auth() {
async function signUpWithEmail() {
setLoading(true);
- const {
- data: { session },
- error,
- } = await supabase.auth.signUp({
- email: email,
- password: password,
- });
+ // Create a username
+ const { data, error } = await supabase.auth.getSession();
if (error) {
Alert.alert(error.message);
} else {
- await supabase
- .from("profiles")
- .upsert({ id: session?.user.id, email: email });
-
- // Create a username
router.replace("/account/choose-username");
- router.setParams({ userId: session?.user.id });
+ router.setParams({
+ userId: data.session?.user.id,
+ email: email,
+ password: password,
+ });
}
setLoading(false);