Require Anonymous
Loading "Creating Protected Routes"
Run locally for transcripts
π¨βπΌ We don't want authenticated users to get confused if they ever land on the
/login
or /signup
pages. So let's prevent that.I want you to make a reusable utility
in that automatically redirects
the user to the home page if they're already logged in.
π§ββοΈ earlier you had written code in the
root.tsx
to get the user's ID from the
session. I created a handy utility in the auth.server.ts
that does that for
you, so you can use that with your utility.π¨βπΌ Thanks Kellie. Once you've made the utility, then I need you to create
loader
s in both
and which use your utility
to redirect the user to the home page if they're already logged in. You'll also
want to include this in the action
s for good measure.π¦ One note, we don't need any data for those routes. In that case, you do still
need to return a
json
response, so you can do this:export async function loader({ request }: LoaderFunctionArgs) {
// use your utility here...
return json({}) // <-- just return an empty object
}