Ask coding questions

← Back to all posts
Is there any way to authenticate users in React?
MatthewDoan1 (333)

Basically the title. I see auth being used mainly on the server-side, but is there any way to use it on the client-side with ReactJS?

ironblockhd (427)

It is possible with fetch and localStorage, here's an example in express:

MatthewDoan1 (333)

@ironblockhd Ah, beautiful example. Thank you so much!

Coder100 (18904)

hmm you still need a backend @ironblockhd

ironblockhd (427)

I think he has a express backend so it's working for this specific question, i agree that the name of my repl is chosen poorly

MatthewDoan1 (333)

@ironblockhd Hm, it doesn't work inside a React component.

ironblockhd (427)

I modified my repl in a way it should work with react, you will need to change the buttonn as specified here:

PattanAhmed (1412)

@MatthewDoan1 Hi,
You will also need Front-End and Back-End


React.js is just Front-End and you need Back-End like HTML, Python, etc.

Hope this helps
Please mark my answer if this helps

Coder100 (18904)

sorry, that is not possible, you will need a backend to parse the header.

MatthewDoan1 (333)

@Coder100 Yea, I'm using an Express backend right now, just for an API to connect to a database (Firestore). I don't want to go through all the redirects and stuff because my app is an SPA. is this still possible?