Code Monkey home page Code Monkey logo

django-rest-authjs's Introduction

Django REST-based Authentication with Auth.js

The repository is split into two directories:

  1. backend -- the backend part of the project (Django, DRF, dj-rest-auth)
  2. frontend -- the frontend part of the project (Next.js, Auth.js)

If you're interested only in Django REST framework authentication take a look at this repo.

Want to learn how to build this?

Check out the post.

Want to use this project?

Go ahead and fork/clone the repository and then setup backend and frontend individually.

Backend

  1. Change directory to backend.

  2. Create and activate a virtual environment:

    $ python3 -m venv venv && source venv/bin/activate
  3. Install the requirements:

    (venv)$ pip install -r requirements.txt
  4. Apply the migrations:

    (venv)$ python manage.py migrate
  5. Register your app with social providers and take note of your client IDs and secrets.

  6. Enter the client IDs and secrets in core/settings.py respectively:

    SOCIALACCOUNT_PROVIDERS = {
        "google": {
            "APP": {
                "client_id": "<your google client id>",
                "secret": "<your google secret>",
                "key": "",  # leave empty
            },
            "SCOPE": [
                "profile",
                "email",
            ],
            "AUTH_PARAMS": {
                "access_type": "online",
            },
            "VERIFIED_EMAIL": True,
        }
    }
  7. Run the development server:

    (venv)$ python manage.py runserver
  8. Your authentication API is now accessible at http://localhost:8000/api/auth/.

Frontend

  1. Change directory to frontend.

  2. Install the dependencies:

    $ npm install
  3. Create an .env.local file in the project root with the following contents:

    NEXTAUTH_URL=http://127.0.0.1:3000
    NEXTAUTH_SECRET=<generate_a_secret_key>
    NEXTAUTH_BACKEND_URL=http://127.0.0.1:8000/api/
    NEXT_PUBLIC_BACKEND_URL=http://127.0.0.1:8000/api/
    
    GOOGLE_CLIENT_ID=<your_google_client_id>
    GOOGLE_CLIENT_SECRET=<your_google_secret>
  4. Run the development server:

    $ next dev
  5. Navigate to http://localhost:3000/ in your favorite web browser.

django-rest-authjs's People

Contributors

duplxey avatar smyja avatar

Stargazers

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

Watchers

 avatar  avatar

django-rest-authjs's Issues

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.