feat: Rollback signup on error, cleanup userDto and comment createdBy

This commit is contained in:
2025-08-11 06:55:55 +02:00
parent 851d0fef46
commit b7b6d02cf2
6 changed files with 14 additions and 20 deletions

View File

@@ -1130,12 +1130,9 @@ components:
type: object type: object
required: required:
- message - message
- createdBy
properties: properties:
message: message:
type: string type: string
createdBy:
$ref: "#/components/schemas/UserDto"
PagedCommentDto: PagedCommentDto:
type: object type: object

View File

@@ -3,15 +3,14 @@ import type { CreateCommentDto, CommentDto } from '~/.api-client'
export function useComment(applicationFormId: string) { export function useComment(applicationFormId: string) {
const commentStore = useCommentStore() const commentStore = useCommentStore()
const { createComment, updateComment } = commentStore const { createComment, updateComment } = commentStore
const { userDto } = useAuth() const { user } = useAuth()
const isEditingComment = ref(false) const isEditingComment = ref(false)
const currentEditedComment = ref<CommentDto | null>(null) const currentEditedComment = ref<CommentDto | null>(null)
const commentTextAreaValue = ref('') const commentTextAreaValue = ref('')
async function submitComment(formElementId: string) { async function submitComment(formElementId: string) {
const newCommentDto: CreateCommentDto = { const newCommentDto: CreateCommentDto = {
message: commentTextAreaValue.value, message: commentTextAreaValue.value
createdBy: userDto.value
} }
try { try {
await createComment(applicationFormId, formElementId, newCommentDto) await createComment(applicationFormId, formElementId, newCommentDto)
@@ -51,7 +50,7 @@ export function useComment(applicationFormId: string) {
} }
function isCommentByUser(comment: CommentDto) { function isCommentByUser(comment: CommentDto) {
return comment.createdBy.id === userDto.value.id return comment.createdBy.id === user.value?.id
} }
return { return {

View File

@@ -50,6 +50,11 @@ export function useAuth() {
fetchOptions: { fetchOptions: {
headers headers
}, },
user: {
deleteUser: {
enabled: true
}
},
plugins: [ plugins: [
organizationClient({ organizationClient({
// Pass the same access control instance and roles to client // Pass the same access control instance and roles to client
@@ -158,25 +163,19 @@ export function useAuth() {
return res return res
} }
const userDto = computed<UserDto>(() => ({
id: user.value?.id ?? '',
name: user.value?.name ?? 'Unknown'
}))
return { return {
session, session,
user, user,
userDto,
loggedIn: computed(() => !!session.value), loggedIn: computed(() => !!session.value),
signIn: client.signIn, signIn: client.signIn,
signUp: client.signUp, signUp: client.signUp,
deleteUser: client.deleteUser,
signOut, signOut,
organization: client.organization, organization: client.organization,
organizations, organizations,
selectedOrganization, selectedOrganization,
options, options,
fetchSession, fetchSession,
fetchJwtAndOrganizations,
client, client,
jwt, jwt,
isPublicRoute, isPublicRoute,

View File

@@ -15,7 +15,7 @@ export function useBetterAuth() {
return Promise.reject() return Promise.reject()
} }
await organization.create( return await organization.create(
{ name, slug, logo }, { name, slug, logo },
{ {
onSuccess: () => { onSuccess: () => {

View File

@@ -86,7 +86,7 @@ import type { StepperItem } from '@nuxt/ui'
const { getAllApplicationFormTemplates } = useApplicationFormTemplate() const { getAllApplicationFormTemplates } = useApplicationFormTemplate()
const { createApplicationForm, submitApplicationForm } = useApplicationForm() const { createApplicationForm, submitApplicationForm } = useApplicationForm()
const { validateFormElements, getHighestComplianceStatus } = useApplicationFormValidator() const { validateFormElements, getHighestComplianceStatus } = useApplicationFormValidator()
const { userDto, selectedOrganization } = useAuth() const { selectedOrganization } = useAuth()
const { canCreateApplicationForm, getCurrentRoleInfo } = usePermissions() const { canCreateApplicationForm, getCurrentRoleInfo } = usePermissions()
const toast = useToast() const toast = useToast()
@@ -196,8 +196,6 @@ async function prepareAndCreateApplicationForm() {
return null return null
} }
applicationFormTemplate.value.createdBy = userDto.value
applicationFormTemplate.value.lastModifiedBy = userDto.value
applicationFormTemplate.value.organizationId = selectedOrganization.value?.id ?? '' applicationFormTemplate.value.organizationId = selectedOrganization.value?.id ?? ''
return await createApplicationForm(applicationFormTemplate.value) return await createApplicationForm(applicationFormTemplate.value)

View File

@@ -27,7 +27,7 @@ definePageMeta({ layout: 'auth' })
useSeoMeta({ title: 'Sign up' }) useSeoMeta({ title: 'Sign up' })
const toast = useToast() const toast = useToast()
const { signUp } = useAuth() const { signUp, deleteUser } = useAuth()
const { createUser } = useUser() const { createUser } = useUser()
const fields = [ const fields = [
@@ -116,8 +116,9 @@ function onSubmit(payload: FormSubmitEvent<Schema>) {
await navigateTo('/') await navigateTo('/')
}, },
onError: (ctx) => { onError: async (ctx) => {
console.log(ctx.error.message) console.log(ctx.error.message)
await deleteUser({ callbackURL: '/signup' })
useToast().add({ useToast().add({
title: 'Fehler bei der Registrierung', title: 'Fehler bei der Registrierung',
description: ctx.error.message, description: ctx.error.message,