import useIsAuthenticated from 'react-auth-kit/hooks/useIsAuthenticated'
export const createCollectionsRoute = new Route({ getParentRoute: () => collectionsLayoutRoute, path: '/create', component: CreateCollection, beforeLoad: async ({ location }) => { const isAuthenticated = useIsAuthenticated() if (!isAuthenticated()) { throw redirect({ to: '/collections', search: { // Use the current location to power a redirect after login // (Do not userouter.state.resolvedLocationas it can // potentially lag behind the actual current location) redirect: location.href, }, }) } },
#how can i check if i iauthenticated
34 messages · Page 1 of 1 (latest)
thats a hook, you need a non hook version of this check
Thanks, and now how can i stay on the same page if i am not auth?
are you sure these are not hooks?
also. to stay on the same page, simply do not redirect
problem with hooks are solved
if i am not redirect than the /create page opens
well you said you want to stay on the same page?
i want to prevert that
i dont have login page, if user tries to access the page that he needs to be loged in, the modal window opens and user can authorize, and i want to prevert the opening of the page that he needs to be loged in
it dosent work for me. if user is not auth i should stay on the same page but right now it routes me to the /create page anyway
i need somehow stay on the previous page, where button was clicked, or redirect to it
prevent the opening of the new page and stay on page where button was clickde
@steep crow
yeas, correct
why not just NOT have a link if you are not authed
or make it look like a link, but it will open a model instead
but i have this button everyware, if i gonna do this in thousand of components, its gonna be bad...
better to do this in routing
make a component that handles it
make it get a string (which will be the path), and there you can do the check if the user is authed, render a LINK component or a model. sounds like simple if else to me
I dont think its possible to do it in the routing, since you already moved to /create.
why i cant just go back in beforeLoad, i think it should be some way
you can go back, what will that achive?
you will go back to the same route you came from
i will be in the previous page, where button was clicked
yeah, what difference does it make? you can also simply not route the user
but gonna handleit in one place, in routing
I dont understand
you have a page, lets call it "nonauthed"
which has a button (link) to another page "create"
you can check in "nonauthed" if the user is authed with a hook.
then, you simply make the button be a link ONLY if he is authed, if not, you will render a "login model" (when clicked)
thank you!