S
Solara11mo ago
conic

Help: Auth Redirect to a new page

I'd like for my application to start on the auth0 login url rather than a solara page if the user is not authenticated. The example for solara auth involves a Button redirect to the login_url
@solara.component
def Page():
if not auth.user.value:
solara.Button("Login", icon_name="mdi-login", href=auth.get_login_url())
@solara.component
def Page():
if not auth.user.value:
solara.Button("Login", icon_name="mdi-login", href=auth.get_login_url())
I'm looking for a redirect function without a button initiating the event.
@solara.component
def Page():
if not auth.user.value:
redirect_to(href=auth.get_login_url())
@solara.component
def Page():
if not auth.user.value:
redirect_to(href=auth.get_login_url())
What are my options?
8 Replies
iisakkirotko
iisakkirotko11mo ago
Take a look at #456, the method mentioned by the OP could work for you, since you'd use an internal route, rather than an external site
Monty Python
Monty Python11mo ago
jpmanson
<:issue_open:882464248951877682> [widgetti/solara] Navigate to URL
I didn't find any way to navigate an external URL directly from the app. Something like for example: solara.use_router().push('https://www.google.com') Although you can create HTML buttons or links to go to other pages, they require a click from the user. It would be very nice if this "navigate to URL" possibility could be added. Thanks
Created
conic
conicOP11mo ago
Thank you for this. Im uncertain what a component vue is just yet. What would that look like? Would I render a component that runs
window.location.href = 'https://solara.dev';
window.location.href = 'https://solara.dev';
?
iisakkirotko
iisakkirotko11mo ago
For instance, yeah A component_vue let's you define a custom solara component based on a vue template, so you can control anything on the front-end
iisakkirotko
iisakkirotko11mo ago
Take a look at the docs page for it: https://solara.dev/examples/general/vue_component
conic
conicOP11mo ago
taking a look if I specify a window redirect in a vue component, would it only do it for the component? Or can it redirect the page for the entire application?
iisakkirotko
iisakkirotko11mo ago
It should redirect the browser completely, although solara.use_router().push() will use solara to load the new page as if the user had navigated to it
conic
conicOP10mo ago
I like this answer as it doesn't require knowledge of vue and is fully python. I'll give it a try. Thanks for your help.
Want results from more Discord servers?
Add your server