Reputation: 439
When a user register an email is sent to them from the API with a token to verify the user. an endpoint of the API requires the token to verify the user, how do I get the token and post it to the API
Upvotes: 1
Views: 1528
Reputation: 39452
Assuming that you have a URL like this in your Email:
https://www.hello.com/verify?token=YOUR_TOKEN_HERE
Let's break it down into steps:
You might have routing implemented that will load a Component for a Specific Route. So you might have something like this:
{ path: 'verify', component: VerifyComponent }
Now in the VerifyComponent
TypeScript Class, you can inject ActivatedRoute
as a Dependency.
import { ActivatedRoute } from '@angular/router'
...
constructor(..., private route: ActivatedRoute) {}
Now in the the ngOnInit
of this Component, you can have access to the token like this:
ngOnInit() {
this.route.queryParams.subscribe(queryParams => {
const token = queryParams['token'];
// Call your Backend API with the token after this
});
}
Upvotes: 3
Reputation: 1698
Include a clickable url in your registrationmail which includes the token as query parameter. e.g. https://website.com/confirmRegistration?token=insertTokenHere
then create a component and a route for /confirmRegistration, inject ActivatedRoute
into that component and read the token with this.route.snapshot.queryParamMap.get('token');
. use the Value to call the API endpoint.
Upvotes: 5