Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we implement a registration by invitation in existing application?

My application supports normal registration for admin roles and registration by invite for team members. Admins can successfully register themselves. Login functionality is also working fine. I am using jwt for token generation and AuthGuards to protect private routes.

Need some help on how I can send an invitation url to users? (nodemailer already configured and working). More concerned about url generation.

Can someone help me? The application backend is in nestjs and frontend is in angular 8. Currently I am testing apis through postman.

Thanks in advance, Ajinkya

like image 321
Ajinkya Ganoo Avatar asked Jan 26 '23 01:01

Ajinkya Ganoo


1 Answers

1) Create a database entity invitation-token with one column token (randomly generated UUID, e.g. with this uuid lib). Set it to self-delete entries after 24 hours. (e.g. TTL in mongodb)

2) Create an endpoint that allows registration with a query param invitation-token,
e.g. /registration?invitation-token=Usa67Nsus78. It only allows registration if the given token exists in the table created in step 1).

3) Create an invite endpoint that takes a mail address as input. It creates a new token in the invitation-token table and sends an email to the given address with a link to the endpoint in 2)

like image 145
Kim Kern Avatar answered Jan 28 '23 16:01

Kim Kern