1
- import Axios , { AxiosError , AxiosResponse } from "axios" ;
2
- import { hostname , userPath } from "./api" ;
3
- import { hashPassword } from "../methods/passwords" ;
1
+ import Axios , { AxiosError , AxiosResponse } from "axios" ;
2
+ import { hostname , userPath } from "./api" ;
3
+ import { hashPassword } from "../methods/passwords" ;
4
4
5
5
export interface IRegisterServerResponse {
6
- httpStatus : number ,
7
- httpMessage : string
8
- outputMessage ?: string
6
+ httpStatus : number ;
7
+ httpMessage : string ;
8
+ outputMessage ?: string ;
9
9
}
10
10
11
- export const registerNewUser = async ( username : string , password : string , passwordConfirmation : string ) : Promise < IRegisterServerResponse > => {
12
-
13
- if ( password !== passwordConfirmation ) {
11
+ export const registerNewUser = async (
12
+ username : string ,
13
+ password : string ,
14
+ passwordConfirmation : string
15
+ ) : Promise < IRegisterServerResponse > => {
16
+ if ( password !== passwordConfirmation ) {
14
17
throw new Error ( "Password did not match passwordConfirmation" ) ;
15
18
}
16
19
let hashedPassword = await hashPassword ( password ) ;
@@ -20,29 +23,28 @@ export const registerNewUser = async (username: string, password: string, passwo
20
23
username : username ,
21
24
password : hashedPassword ,
22
25
confirmationPassword : hashedPassword
23
- }
24
-
26
+ } ;
25
27
26
- return Axios . post ( hostname + userPath + ' /register' , newUser )
28
+ return Axios . post ( hostname + userPath + " /register" , newUser )
27
29
. then ( ( data : AxiosResponse < object > ) => {
28
- console . log ( data )
30
+ console . log ( data ) ;
29
31
const response : IRegisterServerResponse = {
30
32
httpStatus : data . status ,
31
33
httpMessage : data . statusText
32
- }
34
+ } ;
33
35
if ( data . status === 201 ) {
34
- response . outputMessage = "User was successfully created."
36
+ response . outputMessage = "User was successfully created." ;
35
37
}
36
38
resolve ( response ) ;
37
39
} )
38
40
. catch ( ( error : AxiosError ) => {
39
- console . log ( error . response )
41
+ console . log ( error . response ) ;
40
42
const response : IRegisterServerResponse = {
41
43
httpStatus : error . response ! . status ,
42
44
httpMessage : error . response ! . statusText ,
43
45
outputMessage : error . response ! . data . message
44
- }
46
+ } ;
45
47
reject ( response ) ;
46
- } )
47
- } )
48
- }
48
+ } ) ;
49
+ } ) ;
50
+ } ;
0 commit comments