very basics of auth state - not actually authenticating anything right now....

This commit is contained in:
Will Baumbach
2025-08-05 12:04:02 -05:00
parent 813cb44637
commit 409f15f233
8 changed files with 224 additions and 23 deletions

View File

@@ -3,6 +3,9 @@ import { Tabs } from 'expo-router'
import React from 'react'
export default function TabLayout() {
const isAdmin = localStorage.getItem('session') === 'admin'
console.log(isAdmin)
return (
<Tabs
screenOptions={{
@@ -32,15 +35,16 @@ export default function TabLayout() {
options={{
title: 'Posts',
headerShown: false,
tabBarItemStyle: { display: isAdmin ? 'flex' : 'none' },
tabBarIcon: ({ color, focused }) => (
<Ionicons name={focused ? 'rocket-sharp' : 'rocket-outline'} size={24} color={color} />
)
}}
/>
<Tabs.Screen
name='login'
name='profile'
options={{
title: 'Login',
title: 'Profile',
headerShown: false,
tabBarIcon: ({ color, focused }) => (
<Ionicons

View File

@@ -1,66 +0,0 @@
import React from 'react';
import { StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
export default function LoginScreen() {
const [username, setUsername] = React.useState('');
const [password, setPassword] = React.useState('');
function login(username:string, password:string) {
console.log(username, password);
}
return (
<View style={styles.container}>
<Text style={styles.text}>Login</Text>
<View style={{ width: '80%', marginTop: 20 }}>
<Text style={styles.text}>Username</Text>
<TextInput
style={styles.input}
value={username}
placeholder="Enter username"
onChangeText={setUsername}
/>
<Text style={styles.text}>Password</Text>
<TextInput
style={styles.input}
value={password}
placeholder="Enter password"
secureTextEntry
onChangeText={setPassword}
/>
<TouchableOpacity
style={styles.button}
onPress={() => login(username, password)}
>
<Text style={{ color: '#fff', fontWeight: 'bold' }}>Login</Text>
</TouchableOpacity>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#25292e',
justifyContent: 'center',
alignItems: 'center',
},
text: {
color: '#fff',
},
input: {
backgroundColor: '#fff',
borderRadius: 5,
padding: 10,
marginBottom: 15,
},
button: {
backgroundColor: '#1e90ff',
padding: 12,
borderRadius: 5,
alignItems: 'center',
}
});

21
app/(tabs)/profile.tsx Normal file
View File

@@ -0,0 +1,21 @@
import React from 'react'
import { StyleSheet, TouchableOpacity, View } from 'react-native'
import { useSession } from '../ctx'
export default function PostsScreen() {
const { logout } = useSession()
return (
<View style={styles.wrapper}>
<TouchableOpacity onPress={() => logout()}>Logout</TouchableOpacity>
</View>
)
}
const styles = StyleSheet.create({
wrapper: {
flex: 1,
backgroundColor: '#25292e',
padding: 5
}
})