how can i check if i iauthenticated
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, }, }) } },
23 Replies
genetic-orange•2y ago
thats a hook, you need a non hook version of this check
spiritual-aquaOP•2y ago
Thanks, and now how can i stay on the same page if i am not auth?

genetic-orange•2y ago
are you sure these are not hooks?
also. to stay on the same page, simply do not redirect
spiritual-aquaOP•2y ago
problem with hooks are solved
if i am not redirect than the /create page opens
genetic-orange•2y ago
well you said you want to stay on the same page?
spiritual-aquaOP•2y ago
i want to prevert that
genetic-orange•2y ago
well you do that by redirecting
redirect to login or something
spiritual-aquaOP•2y ago
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
genetic-orange•2y ago

spiritual-aquaOP•2y ago
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

spiritual-aquaOP•2y ago
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
@Zion
genetic-orange•2y ago
ohhh
you want to stay on the page BEFORE you click on the link
spiritual-aquaOP•2y ago
yeas, correct
genetic-orange•2y ago
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
spiritual-aquaOP•2y ago
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
genetic-orange•2y ago
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.
spiritual-aquaOP•2y ago
why i cant just go back in beforeLoad, i think it should be some way
genetic-orange•2y ago
you can go back, what will that achive?
you will go back to the same route you came from
spiritual-aquaOP•2y ago
i will be in the previous page, where button was clicked
genetic-orange•2y ago
yeah, what difference does it make? you can also simply not route the user
spiritual-aquaOP•2y ago
but gonna handleit in one place, in routing
genetic-orange•2y ago
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)
spiritual-aquaOP•2y ago
thank you!
❤️