Express, React-Router Auth for one admin user?

Express, React-Router Auth for one admin user?
0

#1

Can someone tell me the best way to go about this problem? My site will have one admin user (there will be NO OTHER users) to be able to CRUD data on the /admin route after the admin logs in. I found this tutorial: https://tylermcginnis.com/react-router-protected-routes-authentication/

but it gave me no luck as I don’t understand the point of the fakeAuth function. Wouldn’t I need to wrap it all into a cookie/JWT? I know I need backend auth somehow and I have the username and pass stored in an environment variable. Just very curious as to how to get a basic backend auth for the admin user, then use react router to redirect after the auth is verified. Any help on this would be much appreciated.


#2

Cookie/jwt &co. are the stuff to imagine to be into fakeAuth :stuck_out_tongue:

That tutorial explain how to render one component or redirect to another route ( hence display another component ) based on the value of a property^^ ( in that case the isAuthenticated property )

The backend auth is what gives you the value of isAuthenticated prop, the two topic are not related^^
Here another tut with all this stuff: Medium : Handle auth with node and passport


#3

But using passport for one person?


#4

Tut was randomly taken honestly, it just had all you need to build an auth flow on an express app :stuck_out_tongue:

That said i see not much difference on set up an auth flow for one single person and a whole pirate crew^^

I mean, at the end of the story that single person must insert some kind of key / password / fingerprint / whatever to authenticate himself right? So why other people cannot do the same with their own credentials?

Maybe the only big diff is that you do not need a db to hold the data, apart that i can’t think of some other meaningful difference ( i am not a security ninja btw, just my impressions^^ )


#5

Protected routes are an important part of any web application. In this post we’ll break down the “Redirects (Auth)” example on the React Router documentation to learn how to create authenticated routes (routes that only certain users can access based on their authentication status) using React Router.