Auth error after having the user logged
Hi everyone I am creating this app that for now only allows the user to log in, I am using python Flask for the backend, the thing is that after logging in without errors a redirect link appears like this: http://localhost:3000/#access_token=eyJhb.... and the browser gives me error for page not found, how can I solve it?
supabase: Client = create_client(supabase_url, supabase_key)
@app.route('/')
def home():
if 'user' in session:
return redirect('/dashboard')
return '''
<a href="/login/github">Login with GitHub</a><br>
<a href="/login/google">Login with Google</a><br>
<a href="/login/microsoft">Login with Microsoft</a>
'''
@app.route('/login/<provider>')
def login(provider):
redirect_uri = 'https://mvtnwpifahffpceqsemj.supabase.co/auth/v1/callback'
auth_url = f"{supabase_url}/auth/v1/authorize?provider={provider}&redirect_to={redirect_uri}"
logging.info(f"Redirect URL: {auth_url}")
return redirect(auth_url)
@app.route('/callback')
def callback():
code = request.args.get('code')
if code:
try:
auth_response = supabase.auth.exchange_code_for_session(code)
user = supabase.auth.user()
session['user'] = user
logging.info(f"User info: {user}")
user_data = {
'email': user['email'],
'name': user['user_metadata']['full_name'],
}
return redirect('/dashboard')
except Exception as e:
logging.error(f"Error during authentication: {str(e)}")
return "Authentication failed", 400
return "Authentication failed", 400
@app.route('/dashboard')
def dashboard():
if 'user' in session:
return f'Sei loggato, {session["user"]["user_metadata"]["full_name"]}! <a href="/logout">Logout</a>'
return redirect('/')
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
app.run(debug=True, port=5000)supabase: Client = create_client(supabase_url, supabase_key)
@app.route('/')
def home():
if 'user' in session:
return redirect('/dashboard')
return '''
<a href="/login/github">Login with GitHub</a><br>
<a href="/login/google">Login with Google</a><br>
<a href="/login/microsoft">Login with Microsoft</a>
'''
@app.route('/login/<provider>')
def login(provider):
redirect_uri = 'https://mvtnwpifahffpceqsemj.supabase.co/auth/v1/callback'
auth_url = f"{supabase_url}/auth/v1/authorize?provider={provider}&redirect_to={redirect_uri}"
logging.info(f"Redirect URL: {auth_url}")
return redirect(auth_url)
@app.route('/callback')
def callback():
code = request.args.get('code')
if code:
try:
auth_response = supabase.auth.exchange_code_for_session(code)
user = supabase.auth.user()
session['user'] = user
logging.info(f"User info: {user}")
user_data = {
'email': user['email'],
'name': user['user_metadata']['full_name'],
}
return redirect('/dashboard')
except Exception as e:
logging.error(f"Error during authentication: {str(e)}")
return "Authentication failed", 400
return "Authentication failed", 400
@app.route('/dashboard')
def dashboard():
if 'user' in session:
return f'Sei loggato, {session["user"]["user_metadata"]["full_name"]}! <a href="/logout">Logout</a>'
return redirect('/')
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
app.run(debug=True, port=5000)