I have a Django GraphQL App which makes use of Djangos Auth System via redirects.
Frontend Vue → GraphQL → Django
For login I call the endpoint myapp.com/auth/login this url is handled by my django app. I redirects then directly to auth0. I then can register or login. (This is working )
I configured the django app like it is described here:
my views looks like this
from django.contrib.auth import logout as log_out
from django.conf import settings
from django.http import HttpResponseRedirect
from urllib.parse import urlencode
from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required
def index(request):
user = request.user
if user.is_authenticated:
return redirect(dashboard)
else:
return redirect(auth_0_login)
def auth_0_login(request):
return redirect(settings.AUTH_0_LOGIN_URL)
@login_required
def dashboard(request):
return redirect(settings.DASHBOARD_URL)
def logout(request):
log_out(request)
return_to = urlencode({'returnTo': request.build_absolute_uri(settings.HOST_URL)})
logout_url = 'https://%s/v2/logout?client_id=%s&%s' % \
(settings.SOCIAL_AUTH_AUTH0_DOMAIN, settings.SOCIAL_AUTH_AUTH0_KEY, return_to)
return HttpResponseRedirect(logout_url)
Now I would like to add an endpoint for registering so that directly the register / sign up tab is shown directly instead of Log in:
I’m not familiar with Django but just tried @Carlos_Mostek 's suggestion here and it works
Here is what you need to do
Add a namespace’d param to your /authorize call (the url that register route will redirect to) to indicate the login page initialScreen configuration option for auth0 Lock used in Universal Login page. for example /authorize?...all_other_params_&mycompany_login_mode=signup
Go to Universal Login section of Auth0 Dashboard and turn on Customize Login Page toggle
Retrieve the namespace’d param be fore you create instance of Auth0Lock var loginMode = config.extraParams.mycompany_login_mode;
set appropriate initialScreen option based on the namespaced param value like initialScreen: loginMode && loginMode === 'signup' ? 'signUp' : undefined,
this namespace’d parameter name can be anything. It can be even weseba. It only reason it is recommended to namespace it so it doesn’t clash with any other param names. One of the way to namespace is to use reverse domain name of your own company as your company domain name is unique. However feel free to use anything you want.