Giter VIP home page Giter VIP logo

fake-api-jwt-json-server's Introduction

JSONServer + JWT Auth

A Fake REST API using json-server with JWT authentication.

Implemented End-points: login,register

Install

$ npm install
$ npm run start-auth

Might need to run

npm audit fix

How to login/register?

You can login/register by sending a POST request to

POST http://localhost:8000/auth/login
POST http://localhost:8000/auth/register

with the following data

{
  "email": "[email protected]",
  "password":"nilson"
}

You should receive an access token with the following format

{
   "access_token": "<ACCESS_TOKEN>"
}

You should send this authorization with any request to the protected endpoints

Authorization: Bearer <ACCESS_TOKEN>

Check out these tutorials:

fake-api-jwt-json-server's People

Contributors

techiediaries avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fake-api-jwt-json-server's Issues

I can't get current user information

Hi. when I make "POST" request to /auth/login I get in response just access token. Is there any way to get also logged in user information. Thanks for help.

Error on login: TypeError: Cannot destructure property `email` of "undefined" or "null"

Hi,

I followed the steps to set up the JWT. Previously I was able to publish the API with the example data, but when it comes to the authentication I came across this error:

curl -d "email=bruno&password=bruno" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:3000/auth/login
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>TypeError: Cannot destructure property `email` of &#39;undefined&#39; or &#39;null&#39;.<br> &nbsp; &nbsp;at server.post (/Users/jose/Documents/www/fake-api/server.js:35:33)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/Users/jose/Documents/www/fake-api/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at next (/Users/jose/Documents/www/fake-api/node_modules/express/lib/router/route.js:137:13)<br> &nbsp; &nbsp;at Route.dispatch (/Users/jose/Documents/www/fake-api/node_modules/express/lib/router/route.js:112:3)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/Users/jose/Documents/www/fake-api/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at /Users/jose/Documents/www/fake-api/node_modules/express/lib/router/index.js:281:22<br> &nbsp; &nbsp;at Function.process_params (/Users/jose/Documents/www/fake-api/node_modules/express/lib/router/index.js:335:12)<br> &nbsp; &nbsp;at next (/Users/jose/Documents/www/fake-api/node_modules/express/lib/router/index.js:275:10)<br> &nbsp; &nbsp;at /Users/jose/Documents/www/fake-api/node_modules/json-server/lib/server/defaults.js:55:5<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/Users/jose/Documents/www/fake-api/node_modules/express/lib/router/layer.js:95:5)</pre>
</body>
</html>

Seems like is not able to get the email from the request. I'm not a node developer and I don't know my way around the code

hi I found why I get wrong email or password error

hi
amazing project , helped me a lot and works easily
I got response 401 wrong email or password
it was because syntax mistake at line 30 of server.js

// Check if the user exists in database
function isAuthenticated({ email, password }) {
------>>>> // return userdb.users.findIndex(user => user.email === email && user.password === password) !== -1 <<<<-------
return userdb.users.findIndex(user => (user.email === email && user.password === password) !== -1)
}

just brackets

function verifyToken return error not throw it

Hi!
When I try to get access to fake-api with this get request
GET http://localhost:3000/products Authorization: Bearer
I get all the data. But I think I shouldn't. I expecting to get an error "jwt must be provided".
I guess code should be corrected some how like this
let verifyTokenResult; try { verifyTokenResult = verifyToken(req.headers.authorization.split(' ')[1]); if (verifyTokenResult instanceof Error) { throw verifyTokenResult; } next()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.