From 0c3f74265a175a397c6ee176b9fecb176ad10a76 Mon Sep 17 00:00:00 2001 From: Stephanie Wong Date: Wed, 18 Oct 2023 02:32:05 -0700 Subject: [PATCH] persist user --- package-lock.json | 52 +++++++++++++++++++ package.json | 1 + src/app/(Authentication)/Login/index.tsx | 3 +- src/app/(Authentication)/SignUp/index.tsx | 5 +- src/app/(BottomTabNavigation)/Cases/index.tsx | 24 +++++++++ src/app/(BottomTabNavigation)/Cases/styles.ts | 6 +++ src/app/index.tsx | 4 +- src/supabase/createClient.ts | 9 ++++ 8 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 src/app/(BottomTabNavigation)/Cases/index.tsx diff --git a/package-lock.json b/package-lock.json index 29ce2c24..d9a0d7f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "impact-fund", "version": "1.0.0", "dependencies": { + "@react-native-async-storage/async-storage": "^1.19.3", "@react-navigation/native": "^6.1.8", "@react-navigation/native-stack": "^6.9.14", "@supabase/supabase-js": "^2.38.0", @@ -3924,6 +3925,17 @@ "react": "^16.8 || ^17.0 || ^18.0" } }, + "node_modules/@react-native-async-storage/async-storage": { + "version": "1.19.3", + "resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.19.3.tgz", + "integrity": "sha512-CwGfoHCWdPOTPS+2fW6YRE1fFBpT9++ahLEroX5hkgwyoQ+TkmjOaUxixdEIoVua9Pz5EF2pGOIJzqOTMWfBlA==", + "dependencies": { + "merge-options": "^3.0.4" + }, + "peerDependencies": { + "react-native": "^0.0.0-0 || 0.60 - 0.72 || 1000.0.0" + } + }, "node_modules/@react-native-community/cli": { "version": "11.3.7", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-11.3.7.tgz", @@ -10651,6 +10663,14 @@ "node": ">=8" } }, + "node_modules/is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "engines": { + "node": ">=8" + } + }, "node_modules/is-plain-object": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", @@ -12193,6 +12213,17 @@ "resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz", "integrity": "sha512-OcjA+jzjOYzKmKS6IQVALHLVz+rNTMPoJvCztFaZxwG14wtAW7VRZjwTQu06vKCYOxh4jVnik7ya0SXTB0W+xA==" }, + "node_modules/merge-options": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz", + "integrity": "sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==", + "dependencies": { + "is-plain-obj": "^2.1.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -19559,6 +19590,14 @@ "@radix-ui/react-compose-refs": "1.0.0" } }, + "@react-native-async-storage/async-storage": { + "version": "1.19.3", + "resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.19.3.tgz", + "integrity": "sha512-CwGfoHCWdPOTPS+2fW6YRE1fFBpT9++ahLEroX5hkgwyoQ+TkmjOaUxixdEIoVua9Pz5EF2pGOIJzqOTMWfBlA==", + "requires": { + "merge-options": "^3.0.4" + } + }, "@react-native-community/cli": { "version": "11.3.7", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-11.3.7.tgz", @@ -24493,6 +24532,11 @@ "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==" }, + "is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==" + }, "is-plain-object": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", @@ -25595,6 +25639,14 @@ "resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz", "integrity": "sha512-OcjA+jzjOYzKmKS6IQVALHLVz+rNTMPoJvCztFaZxwG14wtAW7VRZjwTQu06vKCYOxh4jVnik7ya0SXTB0W+xA==" }, + "merge-options": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz", + "integrity": "sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==", + "requires": { + "is-plain-obj": "^2.1.0" + } + }, "merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", diff --git a/package.json b/package.json index d7b42b67..98d5c9d2 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "ts:check": "tsc" }, "dependencies": { + "@react-native-async-storage/async-storage": "^1.19.3", "@react-navigation/native": "^6.1.8", "@react-navigation/native-stack": "^6.9.14", "@supabase/supabase-js": "^2.38.0", diff --git a/src/app/(Authentication)/Login/index.tsx b/src/app/(Authentication)/Login/index.tsx index a663fdfc..ac19090a 100644 --- a/src/app/(Authentication)/Login/index.tsx +++ b/src/app/(Authentication)/Login/index.tsx @@ -1,8 +1,9 @@ import { router } from 'expo-router'; import React, { useState } from 'react'; import { Text, TextInput, TouchableOpacity, View } from 'react-native'; -import { signInUser } from '../../../supabase/queries/auth'; + import styles from './styles'; +import { signInUser } from '../../../supabase/queries/auth'; export default function LoginScreen() { const [email, setEmail] = useState(''); diff --git a/src/app/(Authentication)/SignUp/index.tsx b/src/app/(Authentication)/SignUp/index.tsx index b919f7b0..613608fb 100644 --- a/src/app/(Authentication)/SignUp/index.tsx +++ b/src/app/(Authentication)/SignUp/index.tsx @@ -2,8 +2,9 @@ import { router } from 'expo-router'; import React, { useState } from 'react'; import { Text, TextInput, View } from 'react-native'; import { TouchableOpacity } from 'react-native-gesture-handler'; -import { signUpUser } from '../../../supabase/queries/auth'; + import styles from './styles'; +import { signUpUser } from '../../../supabase/queries/auth'; export default function SignUpScreen() { const [name, setName] = useState(''); @@ -45,7 +46,7 @@ export default function SignUpScreen() { /> + This is the cases screen! + + + QR Code Scanner + + + signOutUser()} style={styles.button}> + Sign out + + + ); +} + +export default CasesScreen; diff --git a/src/app/(BottomTabNavigation)/Cases/styles.ts b/src/app/(BottomTabNavigation)/Cases/styles.ts index 0cb1df71..d8ce7ec9 100644 --- a/src/app/(BottomTabNavigation)/Cases/styles.ts +++ b/src/app/(BottomTabNavigation)/Cases/styles.ts @@ -7,4 +7,10 @@ export default StyleSheet.create({ alignItems: 'center', justifyContent: 'center', }, + button: { + margin: 10, + alignItems: 'center', + backgroundColor: '#339FFF', + padding: 10, + }, }); diff --git a/src/app/index.tsx b/src/app/index.tsx index b320b51e..3f0012c3 100644 --- a/src/app/index.tsx +++ b/src/app/index.tsx @@ -7,14 +7,14 @@ function StartScreen() { useEffect(() => { supabase.auth.getSession().then(({ data: { session } }) => { if (session) { - router.replace('/Cases/QRCodeScanner'); + router.replace('/Cases'); } else { router.replace('/Welcome'); } }); supabase.auth.onAuthStateChange((_event, session) => { if (session) { - router.replace('/Cases/QRCodeScanner'); + router.replace('/Cases'); } else { router.replace('Welcome'); } diff --git a/src/supabase/createClient.ts b/src/supabase/createClient.ts index 877ccbad..8b5bf219 100644 --- a/src/supabase/createClient.ts +++ b/src/supabase/createClient.ts @@ -1,3 +1,4 @@ +import AsyncStorage from '@react-native-async-storage/async-storage'; import { createClient } from '@supabase/supabase-js'; import 'react-native-url-polyfill/auto'; @@ -7,6 +8,14 @@ if (!process.env.SUPABASE_URL || !process.env.SUPABASE_ANON_KEY) { const supabase = createClient( process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY, + { + auth: { + storage: AsyncStorage, + autoRefreshToken: true, + persistSession: true, + detectSessionInUrl: false, + }, + }, ); export default supabase;