From 62e84b6a74f20ac2b139806d09262203f1d985c4 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 14 Jan 2021 15:46:45 +0200 Subject: Improved and fixed functionality of register --- .../app/components/register/register.component.ts | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/DevHive.Angular') diff --git a/src/DevHive.Angular/src/app/components/register/register.component.ts b/src/DevHive.Angular/src/app/components/register/register.component.ts index 5e4874f..3a59e32 100644 --- a/src/DevHive.Angular/src/app/components/register/register.component.ts +++ b/src/DevHive.Angular/src/app/components/register/register.component.ts @@ -44,20 +44,24 @@ export class RegisterComponent implements OnInit { this.registerUserFormGroup.valueChanges.subscribe(console.log); } - onSubmit(): void { - fetch('http://localhost:5000/api/User/register', { + async onSubmit(): Promise { + const response = await fetch('http://localhost:5000/api/User/register', { method: 'POST', - body: `{ - "UserName": "${this.registerUserFormGroup.get('username')?.value}", - "Email": "${this.registerUserFormGroup.get('email')?.value}", - "FirstName": "${this.registerUserFormGroup.get('firstName')?.value}", - "LastName": "${this.registerUserFormGroup.get('lastName')?.value}", - "Password": "${this.registerUserFormGroup.get('password')?.value}" - }`, + body: JSON.stringify({ + UserName: this.registerUserFormGroup.get('username')?.value, + Email: this.registerUserFormGroup.get('email')?.value, + FirstName: this.registerUserFormGroup.get('firstName')?.value, + LastName: this.registerUserFormGroup.get('lastName')?.value, + Password: this.registerUserFormGroup.get('password')?.value + }), headers: { 'Content-Type': 'application/json' } - }).then(response => response.json()).then(data => { console.log(data); }); + }); + const userCred: string = await response.json(); + + sessionStorage.setItem('UserCred', JSON.stringify(userCred)); + this.router.navigate(['/']); } onRedirectRegister(): void { -- cgit v1.2.3