S
S
Steve2020-02-25 00:38:33
Node.js
Steve, 2020-02-25 00:38:33

How to get data from React token jwt?

If the user successfully logged in, I immediately need to get data from this token, how can this be done?
And there is an intermediate handler, can I get the user object from the request and place it in the state?

//middleware
if(!token){
            return res.redirect('/')
        } else {
            const decrypt = jwt.verify(token, process.env.JWT_SECRET)
            req.user = {
                email: decrypt.email,
                role: decrypt.role,
                balance: decrypt.balance
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jedi, 2020-02-25
@PHPjedi

Googled JWTDecode. Concerning the second. I have an initializer. When the application is loaded, I make a request to /api/me and store the received response in state.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question