-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add methods and events for email verification and password reset (#1048)
## Description - Add `email_verification.created` and `password_reset.created` events - Add `GET /user_management/email_verification/:id` endpoint - Add `GET /user_management/password_reset/:id` and `POST /user_management/password_reset` endpoints - Deprecate current send password reset endpoint ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [x] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required. workos/workos#27414
- Loading branch information
1 parent
6902fa5
commit a57345f
Showing
16 changed files
with
346 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"object": "email_verification", | ||
"id": "email_verification_01H5JQDV7R7ATEYZDEG0W5PRYS", | ||
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS", | ||
"email": "[email protected]", | ||
"expires_at": "2023-07-18T02:07:19.911Z", | ||
"code": "123456", | ||
"created_at": "2023-07-18T02:07:19.911Z", | ||
"updated_at": "2023-07-18T02:07:19.911Z" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"object": "password_reset", | ||
"id": "password_reset_01H5JQDV7R7ATEYZDEG0W5PRYS", | ||
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS", | ||
"email": "[email protected]", | ||
"password_reset_token": "Z1uX3RbwcIl5fIGJJJCXXisdI", | ||
"password_reset_url": "https://your-app.com/reset-password?token=Z1uX3RbwcIl5fIGJJJCXXisdI", | ||
"expires_at": "2023-07-18T02:07:19.911Z", | ||
"created_at": "2023-07-18T02:07:19.911Z" | ||
} |
7 changes: 7 additions & 0 deletions
7
src/user-management/interfaces/create-password-reset-options.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface CreatePasswordResetOptions { | ||
email: string; | ||
} | ||
|
||
export interface SerializedCreatePasswordResetOptions { | ||
email: string; | ||
} |
41 changes: 41 additions & 0 deletions
41
src/user-management/interfaces/email-verification.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export interface EmailVerification { | ||
object: 'email_verification'; | ||
id: string; | ||
userId: string; | ||
email: string; | ||
expiresAt: string; | ||
code: string; | ||
createdAt: string; | ||
updatedAt: string; | ||
} | ||
|
||
export interface EmailVerificationEvent { | ||
object: 'email_verification'; | ||
id: string; | ||
userId: string; | ||
email: string; | ||
expiresAt: string; | ||
createdAt: string; | ||
updatedAt: string; | ||
} | ||
|
||
export interface EmailVerificationResponse { | ||
object: 'email_verification'; | ||
id: string; | ||
user_id: string; | ||
email: string; | ||
expires_at: string; | ||
code: string; | ||
created_at: string; | ||
updated_at: string; | ||
} | ||
|
||
export interface EmailVerificationEventResponse { | ||
object: 'email_verification'; | ||
id: string; | ||
user_id: string; | ||
email: string; | ||
expires_at: string; | ||
created_at: string; | ||
updated_at: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/user-management/interfaces/password-reset.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export interface PasswordReset { | ||
object: 'password_reset'; | ||
id: string; | ||
userId: string; | ||
email: string; | ||
passwordResetToken: string; | ||
passwordResetUrl: string; | ||
expiresAt: string; | ||
createdAt: string; | ||
} | ||
|
||
export interface PasswordResetEvent { | ||
object: 'password_reset'; | ||
id: string; | ||
userId: string; | ||
email: string; | ||
expiresAt: string; | ||
createdAt: string; | ||
} | ||
|
||
export interface PasswordResetResponse { | ||
object: 'password_reset'; | ||
id: string; | ||
user_id: string; | ||
email: string; | ||
password_reset_token: string; | ||
password_reset_url: string; | ||
expires_at: string; | ||
created_at: string; | ||
} | ||
|
||
export interface PasswordResetEventResponse { | ||
object: 'password_reset'; | ||
id: string; | ||
user_id: string; | ||
email: string; | ||
expires_at: string; | ||
created_at: string; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/user-management/serializers/create-password-reset-options.serializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { | ||
CreatePasswordResetOptions, | ||
SerializedCreatePasswordResetOptions, | ||
} from '../interfaces'; | ||
|
||
export const serializeCreatePasswordResetOptions = ( | ||
options: CreatePasswordResetOptions, | ||
): SerializedCreatePasswordResetOptions => ({ | ||
email: options.email, | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/user-management/serializers/email-verification.serializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { | ||
EmailVerification, | ||
EmailVerificationEvent, | ||
EmailVerificationEventResponse, | ||
EmailVerificationResponse, | ||
} from '../interfaces'; | ||
|
||
export const deserializeEmailVerification = ( | ||
emailVerification: EmailVerificationResponse, | ||
): EmailVerification => ({ | ||
object: emailVerification.object, | ||
id: emailVerification.id, | ||
userId: emailVerification.user_id, | ||
email: emailVerification.email, | ||
expiresAt: emailVerification.expires_at, | ||
code: emailVerification.code, | ||
createdAt: emailVerification.created_at, | ||
updatedAt: emailVerification.updated_at, | ||
}); | ||
|
||
export const deserializeEmailVerificationEvent = ( | ||
emailVerification: EmailVerificationEventResponse, | ||
): EmailVerificationEvent => ({ | ||
object: emailVerification.object, | ||
id: emailVerification.id, | ||
userId: emailVerification.user_id, | ||
email: emailVerification.email, | ||
expiresAt: emailVerification.expires_at, | ||
createdAt: emailVerification.created_at, | ||
updatedAt: emailVerification.updated_at, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/user-management/serializers/password-reset.serializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
PasswordReset, | ||
PasswordResetEvent, | ||
PasswordResetEventResponse, | ||
PasswordResetResponse, | ||
} from '../interfaces'; | ||
|
||
export const deserializePasswordReset = ( | ||
passwordReset: PasswordResetResponse, | ||
): PasswordReset => ({ | ||
object: passwordReset.object, | ||
id: passwordReset.id, | ||
userId: passwordReset.user_id, | ||
email: passwordReset.email, | ||
passwordResetToken: passwordReset.password_reset_token, | ||
passwordResetUrl: passwordReset.password_reset_url, | ||
expiresAt: passwordReset.expires_at, | ||
createdAt: passwordReset.created_at, | ||
}); | ||
|
||
export const deserializePasswordResetEvent = ( | ||
passwordReset: PasswordResetEventResponse, | ||
): PasswordResetEvent => ({ | ||
object: passwordReset.object, | ||
id: passwordReset.id, | ||
userId: passwordReset.user_id, | ||
email: passwordReset.email, | ||
expiresAt: passwordReset.expires_at, | ||
createdAt: passwordReset.created_at, | ||
}); |
Oops, something went wrong.