๐Using the Auth Token
Unique identifier which is a JWT format toke, for unique auth purposes, and enhanced security reasons.
Last updated
Unique identifier which is a JWT format toke, for unique auth purposes, and enhanced security reasons.
Last updated
We can use the Authentication Token
received in the previous section, from the app wide state, to then request access to the protected resources in our app, or to the endpoint API or the back-end server. In this section, we will learn how to change the password for the currently logged-in user, using the Authentication Token
received from the endpoint API and which is stored in the Redux Store
.
We can change a user's password by issuing an HTTP POST
request to the Auth setAccountInfo
endpoint. The docs related to this can be found here.
Method: POST
Content-Type: application/json
Endpoint
We need to get the user input containing the new password from the ProfileForm
component. Here we will use useRef
to get the value if the input field. We will then send the newPassword
to the UserProfile
component, where we will send a POST
request to the Firebase end-point API to change the password for the current token
which is stored in the Redux Store
.
Once the user is logged in, we need to navigate to the Profile
page component, where we can change the password for the currently logged in user. After successfully changing the password, we can refresh the app, and try to login using the old password. It should return a Modal / console.log
(based on the logic you have for handling error cases) saying that the password is invalid or something like this : INVALID_PASSWORD
This is how we can use the Authentication Token
for requests to authenticated API end-points. It will depend on the end-point on how the Token
must be added. Sometimes it may need to be added to the request body
, or other times as a query parameter
to the API URL. For some APIs, we may need to add the Authentication Token
to the headers
object! In the end, it depends on the API that you are using.