-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from AdeGneus/feat/forgot-reset-password
feat: add forgot and reset password
- Loading branch information
Showing
6 changed files
with
181 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
ManyToOne, | ||
CreateDateColumn, | ||
UpdateDateColumn, | ||
} from "typeorm"; | ||
import { User } from "./user"; | ||
|
||
@Entity() | ||
export class PasswordResetToken { | ||
@PrimaryGeneratedColumn("uuid") | ||
id: string; | ||
|
||
@Column() | ||
token: string; | ||
|
||
@Column() | ||
expiresAt: Date; | ||
|
||
@ManyToOne(() => User, (user) => user.passwordResetTokens) | ||
user: User; | ||
|
||
@CreateDateColumn() | ||
createdAt: Date; | ||
|
||
@UpdateDateColumn() | ||
updatedAt: Date; | ||
} |
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
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,18 @@ | ||
import crypto from "crypto"; | ||
|
||
const generateResetToken = (): { | ||
resetToken: string; | ||
hashedToken: string; | ||
expiresAt: Date; | ||
} => { | ||
const resetToken = crypto.randomBytes(32).toString("hex"); | ||
const hashedToken = crypto | ||
.createHash("sha256") | ||
.update(resetToken) | ||
.digest("hex"); | ||
const expiresAt = new Date(Date.now() + 10 * 60 * 1000); // 10 minutes from now | ||
|
||
return { resetToken, hashedToken, expiresAt }; | ||
}; | ||
|
||
export default generateResetToken; |