Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: easier logout for development purposes #44

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
import moment from 'moment';
import {Image} from 'expo-image';
import React, {useEffect, useState, type PropsWithChildren} from 'react';
import {ScrollView, StyleSheet, Text, View} from 'react-native';
import {ScrollView, StyleSheet, Text, View, Pressable} from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import MoodScale from '@/components/MoodScale';
import Quote from '@/components/Quote';
import Activities from '@/components/Activities';
import {router} from 'expo-router';

export default function Index() {
const [name, setName] = useState('');

useEffect(() => {
const fetchUserData = async () => {
const storedName = await AsyncStorage.getItem('alias');
setName(storedName || '');
const alias = await AsyncStorage.getItem('alias');
const dob = await AsyncStorage.getItem('dob');
const goals = await AsyncStorage.getItem('goals');
const authToken = await AsyncStorage.getItem('authToken');
const mood = await AsyncStorage.getItem('mood');

setName(alias || ''); // For this page

console.log(alias, dob, goals, authToken, mood); // Logging when you enter the page: for easier development to see current user
};

fetchUserData();
}, []);

return (
<ScrollView style={styles.container}>
<Text style={styles.greeter}>Hey, {name}!</Text>
<Pressable onPress={DevLogoutUser}>
<Text style={styles.greeter}>Hey, {name}!</Text>
</Pressable>
<DiaryHero />
<Section title="Quote of the Day">
<Quote />
Expand Down Expand Up @@ -173,6 +183,22 @@ function Section({title, children}: PropsWithChildren & {title: string}) {
);
}

function DevLogoutUser() {
const removeUserData = async () => {
await AsyncStorage.multiRemove([
'alias',
'authToken',
'dob',
'goals',
'mood',
]); // Remove all user info

router.replace('/login'); // Navigate to login setup screen again
};

removeUserData();
}

const styles = StyleSheet.create({
container: {
padding: 20,
Expand Down
Loading