Redirect on successful registration callback

I’m trying to implement a simple registration page, which would redirect user to login page upon successful registration.

If not, the system prints an error message on the same page.

I’ve not been able to have the redirect and output box in the callbacks outputs because only either of each gets called depending on situation. I managed to get it to work by returning the success message on the same page, but it’s a bit clumsy and suboptimal.

How can I get the page to redirect to login page upon successfus registration?

@app.callback(
    [Output('container-button-basic', "children"),
     #Output('url_loginxx', 'pathname') << cannot get this to work
     ],
    [Input('submit-val', 'n_clicks')],
    [
        State('email_username', 'value'),
        State('password', 'value'),
        State('registration_code', 'value')
    ]
)
def insert_users(n_clicks, email_username, pw, registration_code):
    hashed_password = ''
    if pw is not None: hashed_password = generate_password_hash(pw, method='sha256')
    if email_username is not None and pw is not None and registration_code == 'XXX': #is not None:
        ins = Users_tbl.insert().values(username=email_username, password=hashed_password)
        conn = engine.connect()
        conn.execute(ins)
        conn.close()
        return [html.Div([html.H2('registration successful!'),login])] #return in-page login while the registration box is still there
    else:
        if email_username is not None:
            if '@' not in email_username:
                return [html.Div([html.H2('error: invalid username'),link_to_main])]
        if pw is not None:
            if len(pw) <6:
                return [html.Div([html.H2('error: password too short'), link_to_main])]
        errors = False
        if errors == False: return [html.Div([html.H2(''), link_to_main])]