@@ -26,6 +26,8 @@ export class MyCustomerService extends AbstractService {
2626
2727 router . post ( '/signup' , this . signUp . bind ( this ) )
2828
29+ router . post ( '/login' , this . signIn . bind ( this ) )
30+
2931 parent . use ( `/${ basePath } ` , router )
3032 }
3133
@@ -43,4 +45,27 @@ export class MyCustomerService extends AbstractService {
4345 const result = this . _expandWithId ( request , resource . id )
4446 return response . status ( this . createStatusCode ) . send ( { customer : result } )
4547 }
48+
49+ signIn ( request : Request , response : Response ) {
50+ const { email, password } = request . body
51+ const encodedPassword = Buffer . from ( password ) . toString ( 'base64' )
52+
53+ const result = this . repository . query ( request . params . projectKey , {
54+ where : [ `email = "${ email } "` , `password = "${ encodedPassword } "` ] ,
55+ } )
56+
57+ if ( result . count === 0 ) {
58+ return response . status ( 400 ) . send ( {
59+ message : 'Account with the given credentials not found.' ,
60+ errors : [
61+ {
62+ code : 'InvalidCredentials' ,
63+ message : 'Account with the given credentials not found.' ,
64+ } ,
65+ ] ,
66+ } )
67+ }
68+
69+ return response . status ( 200 ) . send ( { customer : result . results [ 0 ] } )
70+ }
4671}
0 commit comments