-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from pkorchak/add-registration
feat: Call /users/register endpoint after SocialAuthService login
- Loading branch information
Showing
8 changed files
with
248 additions
and
119 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"/api/*": { | ||
"target": " https://03z6w06wwd.execute-api.us-east-1.amazonaws.com/Stage", | ||
"secure": false, | ||
"changeOrigin": true, | ||
"pathRewrite": { | ||
"^/api": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export interface RegisterUserRqDto { | ||
firstName: string; | ||
lastName: string; | ||
email: string; | ||
emailVerified?: boolean; | ||
photoUrl?: string; | ||
provider: IdentityProvider; | ||
} | ||
|
||
export enum IdentityProvider { | ||
INTERNAL = 'INTERNAL', // TODO Add registration by email/password inside of the app | ||
GOOGLE = 'GOOGLE' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface RegisterUserRsDto { | ||
id?: string; | ||
message: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
import { Router } from '@angular/router'; | ||
import { catchError } from 'rxjs/operators'; | ||
|
||
@Injectable({providedIn: 'root'}) | ||
export class HttpService { | ||
|
||
private headers: HttpHeaders = new HttpHeaders({'Content-Type': 'application/json'}); | ||
|
||
constructor(private http: HttpClient, | ||
private router: Router) { | ||
} | ||
|
||
public post(url: string, body: unknown, params?: HttpParams): Observable<unknown> { | ||
return this.handleResponse(this.http.post(url, body, {headers: this.headers, ...params})); | ||
} | ||
|
||
public get(url: string, params?: HttpParams): Observable<unknown> { | ||
return this.handleResponse(this.http.get(url, {headers: this.headers, ...params})); | ||
} | ||
|
||
public patch(url: string, body: unknown, params?: HttpParams): Observable<unknown> { | ||
return this.handleResponse(this.http.patch(url, body, {headers: this.headers, ...params})); | ||
} | ||
|
||
private handleResponse(response: Observable<unknown>): Observable<unknown> { | ||
return response.pipe(catchError(err => this.catchError(err))); | ||
} | ||
|
||
private catchError(error: HttpErrorResponse): Observable<void> { | ||
if (error.status === 401) { | ||
this.router.navigateByUrl('/login'); | ||
} | ||
// TODO Show notification with error text for the user | ||
throw new Error(`${error.statusText}\n${error.message}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { RegisterUserRqDto } from '@model/dto/rq/register-user-rq-dto'; | ||
import { RegisterUserRsDto } from '@model/dto/rs/register-user-rs-dto'; | ||
import { Observable } from 'rxjs'; | ||
import { HttpService } from './http.service'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class UsersHttpService extends HttpService { | ||
|
||
public register(user: RegisterUserRqDto): Observable<RegisterUserRsDto> { | ||
return this.post('/api/users/register', user) as Observable<RegisterUserRsDto>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters