default_url
will get the user if the request is authenticated. If you aren’t seeing that, my guess is that it’s because default_url is being called before the user is authenticated, and is being persisted through login, redirects via the ?next
url parameter, so the value doesn’t get recomputed after authentication has completed.
Try sending unauthenticated users directly to /hub/login, which will result in computing default_url again after successful login, for example:
def default_url(handler):
user = handler.current_user
if not user:
# not logged in, send to login, no ?next
# that way, default_url will be called again after successful login
return handler.get_login_url()
if "admin-ui" in handler.expanded_scopes:
# has permission to view the admin page, send there
return handler.base_url + "hub/admin"
else:
# regular user, send to spawn page
# (which redirects to running user if it's running)
# this is the default default URL
return handler.base_url + "hub/spawn"
c.JupyterHub.default_url = default_url