File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed
Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -148,11 +148,10 @@ export default class User {
148148 this . token = tokenResponse ;
149149 let claims
150150 try {
151- claims = JSON . parse ( atob ( tokenResponse . access_token . split ( "." ) [ 1 ] ) ) ;
151+ claims = JSON . parse ( urlBase64Decode ( tokenResponse . access_token . split ( "." ) [ 1 ] ) ) ;
152152 this . token . expires_at = claims . exp * 1000 ;
153153 } catch ( e ) {
154- console . error ( new Error ( 'Gotrue-js: Failed to parse tokenResponse claims' ) )
155- console . error ( tokenResponse )
154+ console . error ( new Error ( `Gotrue-js: Failed to parse tokenResponse claims: ${ tokenResponse } ` ) )
156155 }
157156 }
158157
@@ -190,3 +189,25 @@ export default class User {
190189 currentUser = null ;
191190 }
192191}
192+
193+ function urlBase64Decode ( str ) { // From https://jwt.io/js/jwt.js
194+ var output = str . replace ( / - / g, '+' ) . replace ( / _ / g, '/' ) ;
195+ switch ( output . length % 4 ) {
196+ case 0 :
197+ break ;
198+ case 2 :
199+ output += '==' ;
200+ break ;
201+ case 3 :
202+ output += '=' ;
203+ break ;
204+ default :
205+ throw 'Illegal base64url string!' ;
206+ }
207+ var result = window . atob ( output ) ; //polifyll https://github.com/davidchambers/Base64.js
208+ try {
209+ return decodeURIComponent ( escape ( result ) ) ;
210+ } catch ( err ) {
211+ return result ;
212+ }
213+ }
You can’t perform that action at this time.
0 commit comments