Encrypted JWT and how to activate Auth::user()
Maulana
Posted on November 19, 2023
I just had an experience that I found interesting
So the boss asked me to encrypt the JWT token sent to the frontend. However, the problem is that when the token is encrypted, the controller cannot use Auth()->user()
What I did was create middleware to decrypt the token sent from the frontend then set to user so that Auth()->user()
can be used in all controllers in the middleware
$token = str_replace('Bearer ', '', $request->header('Authorization'));
$token = Crypt::decrypt($token);
JWTAuth::setToken($token);
JWTAuth::toUser();
Maybe there are more suggestions for friends who are more experienced. Thanks 🌟
💖 💪 🙅 🚩
Maulana
Posted on November 19, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.