mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Fix RLS issue of updating user table
This commit is contained in:
parent
cf5c7d98b9
commit
29ed803ae5
1 changed files with 24 additions and 8 deletions
|
|
@ -45,8 +45,8 @@ import {
|
|||
} from '../../utils/auth'
|
||||
import { createUser } from '../../services/create_user'
|
||||
import { isErrorWithCode } from '../../resolvers'
|
||||
import { initModels } from '../../server'
|
||||
import { getRepository } from '../../entity/utils'
|
||||
import { AppDataSource, initModels } from '../../server'
|
||||
import { getRepository, setClaims } from '../../entity/utils'
|
||||
import { User } from '../../entity/user'
|
||||
import {
|
||||
sendConfirmationEmail,
|
||||
|
|
@ -503,10 +503,21 @@ export function authRouter() {
|
|||
}
|
||||
|
||||
if (user.status === StatusType.Pending) {
|
||||
await getRepository(User).update(
|
||||
{ id: user.id },
|
||||
{ status: StatusType.Active }
|
||||
const updated = await AppDataSource.transaction(
|
||||
async (entityManager) => {
|
||||
await setClaims(entityManager, user.id)
|
||||
return getRepository(User).update(
|
||||
{ id: user.id },
|
||||
{ status: StatusType.Active }
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
if (!updated.affected) {
|
||||
return res.redirect(
|
||||
`${env.client.url}/confirm-email?errorCodes=UNKNOWN`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
res.set('Message', 'EMAIL_CONFIRMED')
|
||||
|
|
@ -612,9 +623,14 @@ export function authRouter() {
|
|||
}
|
||||
|
||||
const hashedPassword = await hashPassword(password)
|
||||
const updated = await getRepository(User).update(
|
||||
{ id: user.id },
|
||||
{ password: hashedPassword }
|
||||
const updated = await AppDataSource.transaction(
|
||||
async (entityManager) => {
|
||||
await setClaims(entityManager, user.id)
|
||||
return getRepository(User).update(
|
||||
{ id: user.id },
|
||||
{ password: hashedPassword }
|
||||
)
|
||||
}
|
||||
)
|
||||
if (!updated.affected) {
|
||||
return res.redirect(
|
||||
|
|
|
|||
Loading…
Reference in a new issue