@@ -34,7 +34,30 @@ class Auth(WebFrameworkAuth):
3434 your project's ``urlpatterns`` list in ``your_project/urls.py``.
3535 """
3636
37- def __init__ (self , * args , ** kwargs ):
37+ def __init__ (
38+ self ,
39+ * args ,
40+ post_logout_view : Optional [callable ] = None ,
41+ ** kwargs ,
42+ ):
43+ """Initialize the Auth class for a Django web application.
44+
45+ :param callable post_logout_view:
46+ Optional.
47+ If not provided, the user will be redirected to the root URL of the app.
48+
49+ If provided, it shall be the view (which is a function)
50+ that will be redirected to, after the user has logged out.
51+ For example, you will typically use this parameter like this::
52+
53+ from . import public_views # This module shall NOT import settings.AUTH
54+ auth = Auth(
55+ ...,
56+ post_logout_view=public_views.my_post_logout_view,
57+ )
58+
59+ where ``my_post_logout_view`` is a Django view function.
60+ """
3861 super (Auth , self ).__init__ (* args , ** kwargs )
3962 route , redirect_view = _parse_redirect_uri (self ._redirect_uri )
4063 self .urlpattern = path (route , include ([
@@ -46,6 +69,7 @@ def __init__(self, *args, **kwargs):
4669 self .auth_response ,
4770 ),
4871 ]))
72+ self ._post_logout_view = post_logout_view
4973
5074 def login (
5175 self ,
@@ -109,8 +133,9 @@ def logout(self, request):
109133 So you can use ``{% url "identity.django.logout" %}`` to get the url
110134 from inside a template.
111135 """
112- return redirect (
113- self ._build_auth (request .session ).log_out (request .build_absolute_uri ("/" )))
136+ return redirect (self ._build_auth (request .session ).log_out (request .build_absolute_uri (
137+ reverse (self ._post_logout_view ) if self ._post_logout_view else "/"
138+ )))
114139
115140 def login_required ( # Named after Django's login_required
116141 self ,
0 commit comments