1
- define ( [ 'exports' , 'aurelia-framework' , 'aurelia-http -client' , './authentication' , './baseConfig' , './oAuth1' , './oAuth2' , './authUtils' ] , function ( exports , _aureliaFramework , _aureliaHttpClient , _authentication , _baseConfig , _oAuth1 , _oAuth2 , _authUtils ) {
1
+ define ( [ 'exports' , 'aurelia-framework' , 'aurelia-fetch -client' , './authentication' , './baseConfig' , './oAuth1' , './oAuth2' , './authUtils' ] , function ( exports , _aureliaFramework , _aureliaFetchClient , _authentication , _baseConfig , _oAuth1 , _oAuth2 , _authUtils ) {
2
2
'use strict' ;
3
3
4
4
Object . defineProperty ( exports , '__esModule' , {
@@ -28,8 +28,8 @@ define(['exports', 'aurelia-framework', 'aurelia-http-client', './authentication
28
28
key : 'getMe' ,
29
29
value : function getMe ( ) {
30
30
var profileUrl = this . auth . getProfileUrl ( ) ;
31
- return this . http . createRequest ( profileUrl ) . asGet ( ) . send ( ) . then ( function ( response ) {
32
- return response . content ;
31
+ return this . http . fetch ( profileUrl ) . then ( status ) . then ( toJson ) . then ( function ( response ) {
32
+ return response ;
33
33
} ) ;
34
34
}
35
35
} , {
@@ -58,7 +58,11 @@ define(['exports', 'aurelia-framework', 'aurelia-http-client', './authentication
58
58
'password' : password
59
59
} ;
60
60
}
61
- return this . http . createRequest ( signupUrl ) . asPost ( ) . withContent ( content ) . send ( ) . then ( function ( response ) {
61
+
62
+ return this . http . fetch ( signupUrl , {
63
+ method : 'post' ,
64
+ body : ( 0 , _aureliaFetchClient . json ) ( content )
65
+ } ) . then ( status ) . then ( toJson ) . then ( function ( response ) {
62
66
if ( _this . config . loginOnSignup ) {
63
67
_this . auth . setToken ( response ) ;
64
68
} else if ( _this . config . signupRedirect ) {
@@ -83,7 +87,10 @@ define(['exports', 'aurelia-framework', 'aurelia-http-client', './authentication
83
87
} ;
84
88
}
85
89
86
- return this . http . createRequest ( loginUrl ) . asPost ( ) . withContent ( content ) . send ( ) . then ( function ( response ) {
90
+ return this . http . fetch ( loginUrl , {
91
+ method : 'post' ,
92
+ body : ( 0 , _aureliaFetchClient . json ) ( content )
93
+ } ) . then ( status ) . then ( toJson ) . then ( function ( response ) {
87
94
_this2 . auth . setToken ( response ) ;
88
95
return response ;
89
96
} ) ;
@@ -114,21 +121,36 @@ define(['exports', 'aurelia-framework', 'aurelia-http-client', './authentication
114
121
var unlinkUrl = this . config . baseUrl ? _authUtils2 [ 'default' ] . joinUrl ( this . config . baseUrl , this . config . unlinkUrl ) : this . config . unlinkUrl ;
115
122
116
123
if ( this . config . unlinkMethod === 'get' ) {
117
- return this . http . createRequest ( unlinkUrl + provider ) . asGet ( ) . send ( ) . then ( function ( response ) {
124
+ return this . http . fetch ( unlinkUrl + provider ) . then ( status ) . then ( toJson ) . then ( function ( response ) {
118
125
return response ;
119
126
} ) ;
120
127
} else if ( this . config . unlinkMethod === 'post' ) {
121
- return this . http . createRequest ( unlinkUrl ) . asPost ( ) . withContent ( provider ) . send ( ) . then ( function ( response ) {
128
+ return this . http . fetch ( unlinkUrl , {
129
+ method : 'post' ,
130
+ body : ( 0 , _aureliaFetchClient . json ) ( provider )
131
+ } ) . then ( status ) . then ( toJson ) . then ( function ( response ) {
122
132
return response ;
123
133
} ) ;
124
134
}
125
135
}
126
136
} ] ) ;
127
137
128
138
var _AuthService = AuthService ;
129
- AuthService = ( 0 , _aureliaFramework . inject ) ( _aureliaHttpClient . HttpClient , _authentication . Authentication , _oAuth1 . OAuth1 , _oAuth2 . OAuth2 , _baseConfig . BaseConfig ) ( AuthService ) || AuthService ;
139
+ AuthService = ( 0 , _aureliaFramework . inject ) ( _aureliaFetchClient . HttpClient , _authentication . Authentication , _oAuth1 . OAuth1 , _oAuth2 . OAuth2 , _baseConfig . BaseConfig ) ( AuthService ) || AuthService ;
130
140
return AuthService ;
131
141
} ) ( ) ;
132
142
133
143
exports . AuthService = AuthService ;
144
+
145
+ function status ( response ) {
146
+ if ( response . status >= 200 && response . status < 300 ) {
147
+ return Promise . resolve ( response ) ;
148
+ } else {
149
+ return Promise . reject ( new Error ( response . statusText ) ) ;
150
+ }
151
+ }
152
+
153
+ function toJson ( response ) {
154
+ return response . json ( ) ;
155
+ }
134
156
} ) ;
0 commit comments