1
0
Fork 0
mirror of synced 2024-10-01 09:38:55 +13:00

Review feedback

This commit is contained in:
Dean 2023-03-07 16:39:26 +00:00
parent ab45e06edb
commit f622c84ebc
3 changed files with 7 additions and 29 deletions

View file

@ -1,11 +1,3 @@
export interface UpdateSelf {
firstName?: string
lastName?: string
password?: string
forceResetPassword?: boolean
onboardedAt?: string
}
export interface SaveUserOpts {
hashPassword?: boolean
requirePassword?: boolean

View file

@ -10,12 +10,7 @@ import {
} from "@budibase/backend-core"
import env from "../../../environment"
import { groups } from "@budibase/pro"
import {
UpdateSelfRequest,
UpdateSelfResponse,
UpdateSelf,
UserCtx,
} from "@budibase/types"
import { UpdateSelfRequest, UpdateSelfResponse, UserCtx } from "@budibase/types"
const { getCookie, clearCookie, newid } = utils
function newTestApiKey() {
@ -122,13 +117,14 @@ export async function getSelf(ctx: any) {
export async function updateSelf(
ctx: UserCtx<UpdateSelfRequest, UpdateSelfResponse>
) {
const body = ctx.request.body
const update = ctx.request.body
const update: UpdateSelf = {
...body,
let user = await userSdk.getUser(ctx.user._id!)
user = {
...user,
...update,
}
const user = await userSdk.updateSelf(ctx.user._id!, update)
user = await userSdk.save(user, { requirePassword: false })
if (update.password) {
// Log all other sessions out apart from the current one

View file

@ -29,7 +29,6 @@ import {
PlatformUserByEmail,
RowResponse,
SearchUsersRequest,
UpdateSelf,
User,
SaveUserOpts,
} from "@budibase/types"
@ -227,15 +226,6 @@ export async function isPreventPasswordActions(user: User) {
return !!(account && isSSOAccount(account))
}
export async function updateSelf(id: string, data: UpdateSelf) {
let user = await getUser(id)
user = {
...user,
...data,
}
return save(user, { requirePassword: false })
}
export const save = async (
user: User,
opts: SaveUserOpts = {}