-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement AuthContext with persistence and stay signed in #7
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: implement AuthContext with persistence and stay signed in #7
Conversation
- Create AuthContext.tsx in utils folder with AsyncStorage persistence - Wrap app with AuthProvider in _layout.tsx - Add login/signup integration with context - Create dashboard page for authenticated users - Implement stay signed in feature with checkbox - Add smart routing based on authentication state - Include loading states and error handling - All code formatted with prettier
|
WHY IS THIS PR SO HUGE |
api/config.ts
Outdated
| @@ -0,0 +1,67 @@ | |||
| // API Configuration for Rails Backend | |||
| const BASE_URL = | |||
| process.env.EXPO_PUBLIC_API_BASE_URL || 'http:/10.2.193.239:3000'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this supposed to be http://
|
Nice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for renaming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also thanks
src/app/auth/login/index.tsx
Outdated
| const handleLogin = async () => { | ||
| try { | ||
| setIsLoading(true); | ||
| console.log('Logging in with:', { email, password }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get rid of this console log. dont want to leak sensitive info
api/config.ts
Outdated
| @@ -0,0 +1,67 @@ | |||
| // API Configuration for Rails Backend | |||
| const BASE_URL = | |||
| process.env.EXPO_PUBLIC_API_BASE_URL || 'http:/10.2.193.239:3000'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets not hardcode our IP into the main branch. can you change the fallback to "http://localhost:3000" instead. your .env should hold your own IP address
src/app/_layout.tsx
Outdated
| <Stack.Screen name="index" options={{ headerShown: false }} /> | ||
| <Stack.Screen name="auth/login" options={{ headerShown: false }} /> | ||
| <Stack.Screen name="auth/signup" options={{ headerShown: false }} /> | ||
| <Stack.Screen name="dashboard" options={{ headerShown: false }} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get rid of the dashboard? it's a good way to check if signup is successful but we are going to change this later.
src/utils/AuthContext.tsx
Outdated
| setDriver(driverData); | ||
|
|
||
| if (staySignedIn) { | ||
| console.log('Saving driver to storage:', driverData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marking
src/utils/AuthContext.tsx
Outdated
| setDriver(newDriver); | ||
|
|
||
| if (staySignedIn) { | ||
| console.log('Saving driver to storage:', newDriver); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marking
| }; | ||
|
|
||
| const logout = async () => { | ||
| console.log('Logging out, clearing storage'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marking
src/app/auth/login/index.tsx
Outdated
| }; | ||
|
|
||
| await login(loginData, staySignedIn); | ||
| console.log('Login successful'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marking
src/app/auth/signup/index.tsx
Outdated
| { text: 'OK', onPress: () => router.push('/dashboard') }, | ||
| ]); | ||
| } catch (error) { | ||
| console.error('Signup error:', error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marking
What's new in this PR
Description
Screenshots
No
How to review
AuthContext.tsx
Next steps
Idk
Relevant links
Online sources
CURSOR!!!
Related PRs
CC: @rachaelch3n