So I have a sso app that handles all the permissions of my microservices.
now whenever I build a page I have to run a function that checks if he has an authorization cookie if yes go ahead if not I need to redirect him depends on to a specific website depending on what the problem is.
now the function runs in the layout function of dash pages.
Any idea how I can redirect the user to another website like you can do in Django for example with HttpResponseRedirect?
Hi @jinnyzor But how do I do that?
I tried using flask redirect but got a dash.exception.InvalidCallbackReturnValue
returned a value having type ‘Response’ which is not JSON serializable
To perform redirects, it needs to be within a request. To do this, you’d need something like:
from flask import Flask, redirect, request
server = Flask(__name__)
@server.before_request
def requestCheck():
if request.method == ‘GET’:
if not criteria:
redirect(target_url)
app = Dash(__name__, server = server)
You can find more server functions here for flask.
I worked with after_request and before_request with some of my stuff. Sometimes I’ll add things to the session cookie with before_request and remove it after_request because it makes it easier to refer to if in the session cookie. But it is too heavy and private to send back to the client browser.
Also, when you open up the server, it allows for really light weight use of post requests, instead of relying on get requests and post requests only going to _dash-update-component.
@jinnyzor
hi man, thanks for waiting, I was on a break from work till today (didn’t return on Saturday and took 2 more days off ) so didn’t have the chance to check your solution till now.
It works! thanks for helping (its the same situation for the CSS post you answered me I am not sure I will be checking it today hopefully by tomorrow I will confirm if it answers my needs but thanks for always helping!)