Skip to content

Commit e939665

Browse files
authored
fix: improve validation and submitting on profile page (#1838)
1 parent 365467f commit e939665

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

app/pages/profile/[identity]/index.vue

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ defineOgImageComponent('Default', {
112112
<!-- Header -->
113113
<header class="mb-8 pb-8 border-b border-border">
114114
<!-- Editing Profile -->
115-
<div v-if="isEditing" class="flex flex-col flex-wrap gap-4">
115+
<form v-if="isEditing" class="flex flex-col flex-wrap gap-4" @submit.prevent="updateProfile">
116116
<label for="displayName" class="text-sm flex flex-col gap-2">
117117
{{ $t('profile.display_name') }}
118118
<input
@@ -145,18 +145,14 @@ defineOgImageComponent('Default', {
145145
</label>
146146
<div class="flex gap-4 items-center font-mono text-sm">
147147
<h2>@{{ profile?.handle }}</h2>
148-
<ButtonBase @click="isEditing = false">
148+
<ButtonBase @click="isEditing = false" type="button">
149149
{{ $t('common.cancel') }}
150150
</ButtonBase>
151-
<ButtonBase
152-
@click="updateProfile"
153-
variant="primary"
154-
:disabled="isUpdateProfileActionPending"
155-
>
151+
<ButtonBase variant="primary" :disabled="isUpdateProfileActionPending" type="submit">
156152
{{ $t('common.save') }}
157153
</ButtonBase>
158154
</div>
159-
</div>
155+
</form>
160156

161157
<!-- Display Profile -->
162158
<div v-else class="flex flex-col flex-wrap gap-4">

server/api/social/profile/[identifier]/index.put.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ export default eventHandlerWithOAuthSession(async (event, oAuthSession) => {
1313

1414
await throwOnMissingOAuthScope(oAuthSession, PROFILE_SCOPE)
1515

16-
const body = parse(ProfileEditBodySchema, await readBody(event))
16+
const requestBody = await readBody(event)
17+
if (requestBody.website && !URL.canParse(requestBody.website)) {
18+
throw createError({ statusCode: 400, statusMessage: 'Invalid website' })
19+
}
20+
21+
const body = parse(ProfileEditBodySchema, requestBody)
1722
const client = new Client(oAuthSession)
1823

1924
const profile = dev.npmx.actor.profile.$build({

0 commit comments

Comments
 (0)