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

Web tokens auth #21

Merged
merged 31 commits into from
Oct 29, 2023
Merged

Web tokens auth #21

merged 31 commits into from
Oct 29, 2023

Conversation

aradradev
Copy link
Collaborator

@aradradev aradradev commented Oct 27, 2023

In this milestone we have implemented the following features:

  • Created get post and delete request for the user

  • Created Cars Controller::API

  • Generated and added the features for the API

  • Tested the API on Postman

  • Authentication for user API:: http://localhost:3000/api/v1/login/ Explanation: This API will make sure that a user logs in to access the page, and it will give secure web tokens and this token can be used to make requests for cars and registrations.

  • token: Authorization type: Bearer.

  • Users API:: http://localhost:3000/api/v1/users/ Explanation: how this API could be used to make a post request and get a new user it uses the last web token to create a new user.

  • Cars API:: http://localhost:3000/api/v1/users/user_id/cars :: API::In-progress...

Explanation and example to use this API::
`import jwt from 'jsonwebtoken';

// Assuming the token is stored in a variable called 'token'
const userToken = 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2vyX2lkIjoxfQ.SRykN3CF-soWGfrD33q0Tme3a--wmGQ5Vl9dohn_fz4';

// Remove 'Bearer ' from the token
const token = userToken.replace('Bearer ', '');

try {
  const decoded = jwt.decode(token);
  const userId = decoded.user_id;
  console.log(`User ID: ${userId}`);
} catch (error) {
  console.error('Error decoding token:', error);
}
You can then use the userId variable to construct the URL for the API requests, like http://localhost:3000/api/v1/users/${userId}/cars. This way, the front end can make requests on behalf of the user while ensuring that each user can only access their own data.

`

Please review the API above and make sure that we can make GET, POST, and DELETE requests.

@aradradev aradradev requested a review from hmunish October 27, 2023 16:52
@aradradev
Copy link
Collaborator Author

@hmunish Do not merge this branch until I finish the full implementation of the auth user

Copy link
Owner

@hmunish hmunish left a comment

Choose a reason for hiding this comment

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

@aradradev, great job implementing user authentication & endpoints for cars. It's time to merge it.

🟢 User authentication working fine.
🟢 Cars API working fine.
🟢 Linters are passing.

@hmunish hmunish merged commit 8ffbddc into dev Oct 29, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants