Coder Social home page Coder Social logo

dotja / authentication_app_react_django_rest Goto Github PK

View Code? Open in Web Editor NEW
94.0 4.0 48.0 12 KB

Authentication app using React and Django REST framework

Python 55.78% HTML 8.42% CSS 3.87% JavaScript 28.82% Shell 1.31% Dockerfile 1.80%
django-rest-framework reactjs sessions

authentication_app_react_django_rest's Introduction

React/DjangoRF Authentication App

Authentication app using React and Django REST framework with session authentication.

Installations

  • backend
pip install djangorestframework
pip install django-cors-headers
  • frontend
npm install axios
npm install react-bootstrap bootstrap

authentication_app_react_django_rest's People

Contributors

dotja 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

Watchers

 avatar  avatar  avatar  avatar

authentication_app_react_django_rest's Issues

Custom class `AppUser` breaks command `./manage.py createsuperuser`, users cannot log into `admin`

Steps to reproduce:

./manage.py createsuperuser
email: [email protected]
username: joe
password: abc321
password: abc321

When trying to log in:
Screenshot from 2024-06-27 12-43-23

Solution:

  1. Add two Boolean fields to the AppUser:
class AppUser(AbstractBaseUser, PermissionsMixin):
	user_id = models.AutoField(primary_key=True)
	email = models.EmailField(max_length=50, unique=True)
	username = models.CharField(max_length=50)

	is_staff = models.BooleanField(default=False)
	is_superuser = models.BooleanField(default=False)

	USERNAME_FIELD = 'email'
	
	objects = AppUserManager()

	def __str__(self) -> str:
		return self.username
  1. Fix create_superuser() method:
class AppUserManager(BaseUserManager):
	def create_superuser(self, email, password=None, **extra_fields):
		if not email:
			raise ValueError('An email is required')
		if not password:
			raise ValueError('A password is required')
		user = self.create_user(email, password)
		user.is_staff = True
		user.is_superuser = True
		user.save()
		return user

Blocked by CORS policy

Hello.

When I submit the form I get the following error:
Access to XMLHttpRequest at 'http://127.0.0.1:8000/api/register' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Please help to solve the problem

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.