Skip to content

Instantly share code, notes, and snippets.

View ManotLuijiu's full-sized avatar
🏠
Working from home

Manot Luijiu ManotLuijiu

🏠
Working from home
View GitHub Profile
@ManotLuijiu
ManotLuijiu / urls.py
Created December 12, 2023 04:46
users -> urls.py
from django.urls import path, re_path
from .views import (
CustomProviderAuthView,
CustomTokenObtainPairView,
CustomTokenRefreshView,
CustomTokenVerifyView,
LogoutView,
)
urlpatterns = [
@ManotLuijiu
ManotLuijiu / views.py
Created December 12, 2023 04:23
users -> views.py
from django.conf import settings
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from djoser.social.views import ProviderAuthView
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
TokenVerifyView,
)
@ManotLuijiu
ManotLuijiu / authentication.py
Created December 12, 2023 03:26
users -> authentication.py
from django.conf import settings
from rest_framework_simplejwt.authentication import JWTAuthentication
class CustomJWTAuthentication(JWTAuthentication):
def authenticate(self, request):
try:
header = self.get_header(request)
if header is None:
raw_token = request.COOKIES.get(settings.AUTH_COOKIE)
@ManotLuijiu
ManotLuijiu / models.py
Created December 11, 2023 10:22
users -> models.py
from django.db import models
from django.contrib.auth.models import (
BaseUserManager,
AbstractBaseUser,
PermissionsMixin,
)
class UserAccountManager(BaseUserManager):
def create_user(self, email, password=None, **kwargs):
@ManotLuijiu
ManotLuijiu / urls.py
Created December 11, 2023 09:58
django_auth -> urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("api/", include("djoser.urls")),
path("api/", include("users.urls")),
]
@ManotLuijiu
ManotLuijiu / .env.local
Last active December 12, 2023 08:27
django_auth/settings.py
DOMAIN="localhost:3000
DJANGO_SECRET_KEY="my-django-secret-key"
CLOUDINARY_CLOUD_NAME=""
CLOUDINARY_API_KEY=""
CLOUDINARY_API_SECRET=""
REDIRECT_URLS="http://localhost:3000/auth/google,http://localhost:3000/auth/facebook"
@ManotLuijiu
ManotLuijiu / .flake8
Last active February 12, 2024 02:26
flak8
[flake8]
extend-ignore = E501
@ManotLuijiu
ManotLuijiu / settings.json
Created October 17, 2023 03:04
settings.json for python env
{
"files.autoSave": "afterDelay",
"editor.fontSize": 16,
"terminal.integrated.fontFamily": "AnonymicePro Nerd Font",
"editor.fontFamily": "AnonymicePro Nerd Font",
"terminal.integrated.fontSize": 16,
"editor.formatOnSave": true,
"editor.formatOnType": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.wordWrap": "on",
@ManotLuijiu
ManotLuijiu / appA-appB.js
Last active August 27, 2023 05:49
sharing Auth among Apps
// In protected routes of App A and App B
import { validateToken } from './path-to-shared-auth-service';
// Middleware to check token before accessing protected routes
async function requireAuthentication(req, res, next) {
const token = req.cookies.authToken; // Retrieve token from cookies
const isValidToken = await validateToken(token);
if (isValidToken) {
@ManotLuijiu
ManotLuijiu / hydration-error.txt
Created August 21, 2023 04:21
hydration-error in nextjs 13.4
https://nextjs.org/docs/messages/react-hydration-error