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] created AuthContext #20

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

rachaelch3n
Copy link
Contributor

What's new in this PR 🧑‍🌾

Description

  • Implemented AuthContext to manage user authentication state
  • Added AuthProvider to wrap components and provide sign-in, sign-up, and sign-out functionality
  • Signing in reroutes to dashboard that confirms user is signed in, and users now have the option to sign out

Screenshots

Screen Shot 2024-10-22 at 6 57 56 PM Screen Shot 2024-10-22 at 6 57 32 PM

How to review

  • Review the AuthProvider implementation in utils/AuthProvider.tsx
  • Test the login flow in LoginPage.tsx and ensure signUp and signIn work as expected
  • Test the Dashboard component in DashboardPage.tsx to verify it correctly displays user data (e.g., email) and handles the sign-out process

Next steps

  • Styling

Relevant links

Online sources

Related PRs

CC: @ccatherinetan

@@ -14,9 +14,10 @@
"pre-commit": "(pnpm run tsc || true) && (pnpm run lint || true) && pnpm run prettier"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @ccatherinetan, maybe we want to remove this change & also the package-lock.json change? (do we want/need this change)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pragyakallanagoudar what change are you referring to?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is fully on the wrong line lol but i'm referring to the one on line 17/20 of this file

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sg! we'll delete the @next/swc-darwin-arm64 line

Copy link

@ronniebeggs ronniebeggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far! I left a few comments and I imagine @ccatherinetan will also want to review soon as well. Good job!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ccatherinetan It seems that devs may've accidentally used npm commands and now we have both npm and pnpm lock files. This may cause dependency issues in the future. I'd look into cleaning up the repository by deleting this package-lock.json file.


// Define the shape of the context
interface AuthContextType {
authUser: any;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create an AuthUser type/interface that contains user profile related attributes. This will get rid of the eslint error.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The authUser attribute would likely have an AuthUser | null type.

Comment on lines 95 to 96
setAuthUser(null);
setIsLoggedIn(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider when a logout event is sent from the server. This should redirect a user to the /login screen.

@@ -14,9 +14,10 @@
"pre-commit": "(pnpm run tsc || true) && (pnpm run lint || true) && pnpm run prettier"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pragyakallanagoudar what change are you referring to?

Comment on lines +6 to +12
export default function LoginLayout() {
return (
<AuthProvider>
<Login />
</AuthProvider>
);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only need to wrap the layout.tsx file with the AuthProvider to give its child screens access to context data. It seems that an Auth context would need to wrap the entire app, so look into wrapping the root layout.tsx file with the auth provider.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1! See outermost layout.tsx in IJP's codebase

Comment on lines 27 to 30
<p>User is currently: {isLoggedIn ? 'Logged In' : 'Logged Out'}</p>
{authUser && <p>User name: {authUser.email}</p>}{' '}
{/* Display user's email */}
<button onClick={signOut}>Log Out</button> {/* Logout button */}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: it's better to have separate pages/flows for logged in/out users. However, this page looks like it'll be changed in the future, so keep this in mind when/if it does change.

Copy link

@pragyakallanagoudar pragyakallanagoudar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work @rachaelch3n ! have just left some comments / questions

Comment on lines +6 to +12
export default function LoginLayout() {
return (
<AuthProvider>
<Login />
</AuthProvider>
);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1! See outermost layout.tsx in IJP's codebase

@@ -0,0 +1,5 @@
import { AuthProvider } from '../../utils/AuthProvider';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably get rid of this whole file when you move the <AuthProvider> wrap out to the outer layout.tsx.


// Define the shape of the context
interface AuthContextType {
authUser: any;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ronniebeggs curious if you have thoughts on whether storing the AuthUser object vs. the Session in the AuthContext would be better? i did the latter in ijp but tbh i have no idea why

@ccatherinetan ccatherinetan linked an issue Oct 26, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Auth Context
4 participants