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

Front end #28

Merged
merged 28 commits into from
Sep 15, 2024
Merged

Front end #28

merged 28 commits into from
Sep 15, 2024

Conversation

RadouaneAbn
Copy link
Collaborator

Pull Request Description

Changes Made

  • add PrivateRoute to secure the private routes
    • apply a authentication method that send the token if it exists to with a get request to /auth_validate to check the validity of the token
    • use open={true} to make the secure route accessible login/logout experience
  • use useContext to manage teh state of the app by providing variable that can be accessed from with in the context provider

Related Issue

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Additional Notes

ila36IX and others added 28 commits September 14, 2024 18:18
This update wraps the app component in a ContextProvider to enable global state sharing across components, improving state handling.
  isAuthenticated: (default: false): this variable will be set to true if the use is authenticated using (PrivateRoute)
  user: (defaul: null): This will be the users first and last name and the avatar
  setAuth: to update the value of isAuthenticated
  setUser: updates teh value of user

Return:
  return the context provider with the above variables and functions
in the right top corner:
  instead of just displaying the profile and saved buttons
  we will check if the user authenticated (PrivateRoute)

  if the user is authenticated (isAuthenticated = true) the profile and saved buttons will be displayed
  else display login button
- Created PrivateRoute component to manage route access based on user authentication status.
- Utilizes DataContext to retrieve and update authentication state (isAuthenticated, setAuth, setUser).
- Checks token validity by making an API request to /api/auth_validate.
- Renders component if user is authenticated or redirects to /auth if not.
- Supports public routes via the "open" prop, allowing unrestricted access when set to true.
add a handleSubmit for both signin and signup forms

- Added form submission handler to validate all fields before submitting.

Signup:

- send a post request to the api/register route with the information needed to create a new user
- if the return is 201 (created) the user will be prompt with the login window
- else an error message will be displayed describing the error

Signin:

- send a post request to the api/login route with the information needed to log user {email, password}
- the return of this requets in a success is {token, 'token...'} or an error: message
- if the return status is 200 the token will be saved in the local storage of the browser
  and the user will be redirected to home
- else the field will be create for a new input
Copy link
Collaborator

@Badr-Annabi Badr-Annabi left a comment

Choose a reason for hiding this comment

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

Fantastic Job

@Badr-Annabi Badr-Annabi merged commit 9843e8b into dev Sep 15, 2024
1 check failed
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.

3 participants