Skip to content

Instantly share code, notes, and snippets.

@yeazin
Last active September 24, 2021 09:42
Show Gist options
  • Save yeazin/9f51314fcdb23c5908bb4a34af5d40d8 to your computer and use it in GitHub Desktop.
Save yeazin/9f51314fcdb23c5908bb4a34af5d40d8 to your computer and use it in GitHub Desktop.
Django REST Framework Custom Decorators
'''
Resources
Simple JWT Token bearer authentication : https://gist.github.com/ridvanaltun/6e3a7513519f998bd3f770c117e18f07
custom Decorators : https://docs.djangoproject.com/en/2.2/topics/class-based-views/intro/#decorating-the-class
'''
from django.http import response
from functools import wraps
## is authenticated
def IsLogin(func):
@wraps(func)
def wrapper(request,*args,**kwargs):
'''
Checking the auth if user has bearer token or not
'''
if not 'Authorization' in request.headers:
return response.JsonResponse({'Error':'Sorry Your Not loged IN'})
else:
return func(request,*args,**kwargs)
return wrapper
@yeazin
Copy link
Author

yeazin commented Sep 24, 2021

Do you have any Query?
join me then

Linkedin : yeazin
facebook : yeazin
email : naz.yeasin@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment