Giter VIP home page Giter VIP logo

nextjs-jwt's Introduction

NextJS-JWT

A JWT-Auth app created with Next.js and Redux.
This app works with an API created with Rails, but you can change it here to works with your API.

Usage:

Instalation:

Make sure you have Node and NPM installed. Also that you have the API

git clone https://github.com/dmunoz-10/Nextjs-JWT.git
cd nextjs-jwt
npm install

Starting the app:

# Run in dev mode:
npm run dev

# Run in production:
npm run build
npm start

How to work it with your API:

Folder Structure:

.
├── components
│   ├── Layout.js
│   └── Navbar.js
├── node_modules
│   ├── [...]
├── pages
│   └── _app.js
|   └── index.js
|   └── me.js
|   └── signin.js
|   └── signup.js
├── redux
│   └── actions
│       └── authActions.js
│       └── index.js
│   └── reducers
│       └── authReducer.js
│       └── index.js
│   └── index.js
│   └── types.js
├── utils
│   └── cookie.js
│   └── initialize.js
├── config.js
├── next.config.js
├── package-lock.json
├── package.json
├── README.md
└── server.js
  • Change the API's URL: Go to ./config.js and you can change it:

    module.exports = {
        API: 'http://localhost:3000/api/v1',
    };
    
  • Change the Endpoints: Go to ./redux/actions/authActions.js

    • Sign up:

      22    axios.post(`${API}/users`, {
      

    • Sign in:

      67    axios.post(`${API}/users/authenticate`, {
      

      Note: To change the way how you extract the token:

      72    setCookie('token', response.data.auth_token);
      73    Router.push('/me');
      74    dispatch({type: AUTHENTICATE, payload: response.data.auth_token});
      

    Go to ./pages/me.js

    • Show the User's data:

      43    const response = await axios.get(`${API}/user/me`, {
      

      Note: To change the way how you extract the data:

      48    const user = await response.data.user;
      

TODO

  • Add the API that uses JWT for Authentication.
  • Show the errors validations in the Sign up and Sign in pages

nextjs-jwt's People

Contributors

dmunoz-10 avatar dependabot[bot] avatar

Stargazers

halil kesgin avatar Arshkhan Pathan avatar  avatar HelloBagus avatar Ciel Yu avatar Hiren Ghodasara avatar

Watchers

James Cloos avatar

Forkers

axel225587

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.