Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/server/src/enterprise/database/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ export class User {
@Column({ type: 'text', nullable: true, unique: true })
tempToken?: string | null

@CreateDateColumn({ nullable: true })
@Column({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error still persists.

Image

type: 'datetime',
nullable: true,
default: null,
transformer: {
to: (v: Date | null | undefined): string | null => (v instanceof Date ? v.toISOString() : null),
from: (v: string | Date | null): Date | null => {
if (!v) return null
return v instanceof Date ? v : new Date(v)
}
}
})
tokenExpiry?: Date | null

@Column({ type: 'varchar', length: 20, default: UserStatus.UNVERIFIED })
Expand Down
12 changes: 8 additions & 4 deletions packages/server/src/enterprise/services/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ export class AccountService {
const user = await this.userService.readUserByToken(data.user.tempToken, queryRunner)
if (!user) throw new InternalFlowiseError(StatusCodes.NOT_FOUND, UserErrorMessage.USER_NOT_FOUND)
data.user = user
data.user.tempToken = ''
data.user.tempToken = null
data.user.tokenExpiry = null
data.user.status = UserStatus.ACTIVE
data.user = await this.userService.saveUser(data.user, queryRunner)
Expand Down Expand Up @@ -568,12 +568,16 @@ export class AccountService {
const queryRunner = this.dataSource.createQueryRunner()
await queryRunner.connect()
try {
if (!data.user.tempToken) throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, UserErrorMessage.INVALID_TEMP_TOKEN)

const user = await this.userService.readUserByEmail(data.user.email, queryRunner)
if (!user) throw new InternalFlowiseError(StatusCodes.NOT_FOUND, UserErrorMessage.USER_NOT_FOUND)
if (user.tempToken !== data.user.tempToken)
if (!user.tempToken || user.tempToken !== data.user.tempToken)
throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, UserErrorMessage.INVALID_TEMP_TOKEN)

const tokenExpiry = user.tokenExpiry
if (!tokenExpiry) throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, UserErrorMessage.INVALID_TEMP_TOKEN)

const now = moment()
const expiryInMins = process.env.PASSWORD_RESET_TOKEN_EXPIRY_IN_MINUTES
? parseInt(process.env.PASSWORD_RESET_TOKEN_EXPIRY_IN_MINUTES)
Expand All @@ -592,8 +596,8 @@ export class AccountService {
const hash = bcrypt.hashSync(password, salt)
data.user = user
data.user.credential = hash
data.user.tempToken = ''
data.user.tokenExpiry = undefined
data.user.tempToken = null
data.user.tokenExpiry = null
data.user.status = UserStatus.ACTIVE

await queryRunner.startTransaction()
Expand Down