diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e2798e4..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "editor.codeActionsOnSave": { - "source.fixAll": "explicit", - "source.organizeImports": "explicit", - "source.sortMembers": "explicit" - } -} diff --git a/app.json b/app.json index b052536..9715ee8 100644 --- a/app.json +++ b/app.json @@ -5,7 +5,7 @@ "version": "1.0.0", "orientation": "portrait", "icon": "./assets/images/icon.png", - "scheme": "myapp", + "scheme": "com.techtracker", "userInterfaceStyle": "automatic", "newArchEnabled": true, "ios": { @@ -34,7 +34,8 @@ "resizeMode": "contain", "backgroundColor": "#ffffff" } - ] + ], + "expo-secure-store" ], "experiments": { "typedRoutes": true diff --git a/components/Account.tsx b/components/Account.tsx new file mode 100644 index 0000000..9b68b4a --- /dev/null +++ b/components/Account.tsx @@ -0,0 +1,120 @@ +import { useState, useEffect } from 'react' +import { supabase } from '../lib/supabase' +import { StyleSheet, View, Alert } from 'react-native' +import { Button, Input } from '@rneui/themed' +import { Session } from '@supabase/supabase-js' + +export default function Account({ session }: { session: Session }) { + const [loading, setLoading] = useState(true) + const [username, setUsername] = useState('') + const [website, setWebsite] = useState('') + const [avatarUrl, setAvatarUrl] = useState('') + + useEffect(() => { + if (session) getProfile() + }, [session]) + + async function getProfile() { + try { + setLoading(true) + if (!session?.user) throw new Error('No user on the session!') + + const { data, error, status } = await supabase + .from('profiles') + .select(`username, website, avatar_url`) + .eq('id', session?.user.id) + .single() + if (error && status !== 406) { + throw error + } + + if (data) { + setUsername(data.username) + setWebsite(data.website) + setAvatarUrl(data.avatar_url) + } + } catch (error) { + if (error instanceof Error) { + Alert.alert(error.message) + } + } finally { + setLoading(false) + } + } + + async function updateProfile({ + username, + website, + avatar_url, + }: { + username: string + website: string + avatar_url: string + }) { + try { + setLoading(true) + if (!session?.user) throw new Error('No user on the session!') + + const updates = { + id: session?.user.id, + username, + website, + avatar_url, + updated_at: new Date(), + } + + const { error } = await supabase.from('profiles').upsert(updates) + + if (error) { + throw error + } + } catch (error) { + if (error instanceof Error) { + Alert.alert(error.message) + } + } finally { + setLoading(false) + } + } + + return ( + + + + + + setUsername(text)} /> + + + setWebsite(text)} /> + + + +