Skip to main content

A Django package that provides 'out-of-the-box' JWT auth, user, group, and permission APIs for use in Single Page Apps (eg - Vue, React).

Project description

Django SPA Day

Coverage

A Django package that provides "out-of-the-box" basic auth, user, group, and permission APIs for use in Single Page Apps (eg - Vue, React).

So easy, you can take a SPA day!

django-spaday deliberately stays below version 1.x.x to signal that every new version may potentially have breaking changes.

NOTE: django-spaday is very opinionated as its for internal use.

Features

  • Auth (login/logout/change password)
  • User management w/permissions
  • Group management w/permissions
  • Audit Log (optional)
  • Django Celery Results (optional)

Requirements

Assumes you have started from this cookiecutter-django template which leverages the following.

  • dj-rest-auth
  • django-auditlog
  • django-celery-results
  • django-cors-headers
  • django-filter
  • djangorestframework
  • djangorestframework-simplejwt
  • django-perm-filter

Quickstart

Install Django SPA Day:

python3 -m pip install django-spaday

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'django_spaday',
)

Settings

In config/urls.py add the urls:

urlpatterns = [
    path(r"djadmin/", admin.site.urls),
    ...
    path("", include("django_spaday.urls")),
]

In config/api_router.py add the API urls:

urlpatterns = [
    path("", include("django_spaday.api.urls")),
    # Place all your app's API URLS here.
    ...
    path("auth/", include("dj_rest_auth.urls")),
]

In config/settings/base.py ensure your dj-rest-auth settings include the following:

REST_AUTH = {
    "USE_JWT": True,
    "SESSION_LOGIN": False,
    "TOKEN_MODEL": None,
    "USER_DETAILS_SERIALIZER": "django_spaday.api.serializers.UserAuthSerializer",
    "JWT_AUTH_HTTPONLY": False,  # False means js can access the cookie
}

NOTE: This is imporatant as it will provide the frontend app with the logged in User's permissions, etc.

Overrides

These are the SPA_DAY defaults and do not need to be specified in settings unless you wish to override.

SPA_DAY = {
    "PERMISSION_SERIALIZER": "django_spaday.api.serializers.PermissionListSerializer",
    "USER_SERIALIZER": "django_spaday.api.serializers.UserSerializer",
    "GROUP_SERIALIZER": "django_spaday.api.serializers.GroupSerializer",
    "CHANGE_PASSWORD_SERIALIZER": "django_spaday.api.serializers.ChangePasswordSerializer",
    "USER_AUTH_SERIALIZER": "django_spaday.api.serializers.UserAuthSerializer",
    "LAST_LOGIN_SERIALIZER": "django_spaday.api.serializers.LastLoginSerializer",
}
make env
make pip_install
make migrations
make migrate
make superuser
make serve

or simply make from_scratch

  • Visit http://127.0.0.1:8000/djadmin/ for the Django Admin
  • Visit http://127.0.0.1:8000/api/docs/ for the API docs

Testing

make pytest
make coverage
make open_coverage

Issues

If you experience any issues, please create an issue on Github.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.1.4] - 2025-02-20

  • Override dj_rest_auth LoginView to trigger Django's built in user_logged_in signal.

[0.1.3] - 2024-04-02

  • Moved to ruff and added tests

[0.1.2] - 2024-03-07

  • Added missing template example (assumes your Vue project has been built to project/static/vue-frontend)

[0.1.1] - 2024-03-07

  • Added test coverage

[0.1.0] - 2022-04-19

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_spaday-0.1.4.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_spaday-0.1.4-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file django_spaday-0.1.4.tar.gz.

File metadata

  • Download URL: django_spaday-0.1.4.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.11

File hashes

Hashes for django_spaday-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2a1a333accc3acd9ab0fdb3e0733718fde88431ca9b039ed8a99c1f1a6c6e51a
MD5 b298ad0f0fcd1a39dea54a6c33df157f
BLAKE2b-256 ee6f16eeaeaf36e85770ceb641b7138118df07afb4a2abe70fe4197b7432e605

See more details on using hashes here.

File details

Details for the file django_spaday-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: django_spaday-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.11

File hashes

Hashes for django_spaday-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d1a1a3a36ace0656e763e862003364ac67963c618198a35dc5981c9c7aad3e41
MD5 c837bd55fc42914cedddcba99b011ff9
BLAKE2b-256 d5863976394c38b2471cfbde43b943291e97ff1072a025be4cbcafb111658edb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page