You are on the right track using JWT. About how secure it is, is to ask yourself, how do you send the data from the frontend, did you validate each of the given input or not, and how the token is stored, and where, does the token static or has an expiration date that needs a refresh every each the given interval.
To avoid a user updating another user's profile, you need to add more security layer like model policy, or gate, and do check the sender id with the requested data's owner id (or user id). Laravel has you covered with that in mind. Please refer to the docs.
You can also make a refresh token method (i believe it was already implemented on the JWT package) and add an expiration date for each the given token then do refresh from the client side when it expires, it might seems like a bit of an extra work, but it is recommended and considered as good practice for security.
And you don't need to do Auth::check()
all the time, just use a middleware provided by the plugin you are using and use auth()->user()
or Auth::user()
to get the current authenticated user's data.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…