From 3c9ea75bb1b211157081a896932555c74980dd78 Mon Sep 17 00:00:00 2001 From: "dayo.ogundipe" Date: Sat, 16 Mar 2024 08:57:24 -0700 Subject: [PATCH] register bug source of null --- API/Controllers/AccountController.cs | 4 +++- client-app/src/features/errors/ValidationErrors.tsx | 2 +- client-app/src/features/users/RegisterForm.tsx | 7 +++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/API/Controllers/AccountController.cs b/API/Controllers/AccountController.cs index 73f14e6..1770f38 100644 --- a/API/Controllers/AccountController.cs +++ b/API/Controllers/AccountController.cs @@ -82,10 +82,12 @@ public async Task>GetCurrentUser(){ private UserDto CreateUserObject(AppUser user) { + + var photo = user.Photos!=null? user.Photos.FirstOrDefault(x=>x.IsMain)?.Url: ""; return new UserDto { DisplayName = user.DisplayName, - Image = user.Photos.FirstOrDefault(x=>x.IsMain)?.Url, + Image = photo, Token = _tokenSerivce.CreateToken(user), Username = user.UserName diff --git a/client-app/src/features/errors/ValidationErrors.tsx b/client-app/src/features/errors/ValidationErrors.tsx index 663b702..5580d8c 100644 --- a/client-app/src/features/errors/ValidationErrors.tsx +++ b/client-app/src/features/errors/ValidationErrors.tsx @@ -7,7 +7,7 @@ interface Props { export default function ValidationError({ errors }: Props) { return ( - {errors && ( + {Array.isArray(errors) && ( {errors.map((err: string, i) => ( {err} diff --git a/client-app/src/features/users/RegisterForm.tsx b/client-app/src/features/users/RegisterForm.tsx index c7026a7..861beb3 100644 --- a/client-app/src/features/users/RegisterForm.tsx +++ b/client-app/src/features/users/RegisterForm.tsx @@ -7,7 +7,7 @@ import * as Yup from "yup"; import ValidationError from "../errors/ValidationErrors"; export default observer(function RegisterForm() { - const { userStore } = useStore(); + const { userStore, modalStore } = useStore(); return ( - userStore.register(values).catch((error) => setErrors({ error })) + userStore.register(values).catch((error) => { + modalStore.closeModal(); + setErrors({ error }); + }) } validationSchema={Yup.object({ displayName: Yup.string().required(),