@@ -20,8 +20,6 @@ export type RemoteConnector = {
20
20
const POWERSYNC_TRAILING_SLASH_MATCH = / \/ + $ / ;
21
21
const POWERSYNC_JS_VERSION = PACKAGE . version ;
22
22
23
- // Refresh at least 30 sec before it expires
24
- const REFRESH_CREDENTIALS_SAFETY_PERIOD_MS = 30_000 ;
25
23
const SYNC_QUEUE_REQUEST_LOW_WATER = 5 ;
26
24
27
25
// Keep alive message is sent every period
@@ -122,21 +120,11 @@ export abstract class AbstractRemote {
122
120
}
123
121
124
122
async getCredentials ( ) : Promise < PowerSyncCredentials | null > {
125
- const { expiresAt } = this . credentials ?? { } ;
126
- const currentTime = new Date ( new Date ( ) . valueOf ( ) + REFRESH_CREDENTIALS_SAFETY_PERIOD_MS ) ;
127
- if ( expiresAt && expiresAt > currentTime ) {
123
+ // If we have credentials stored, return them.
124
+ if ( this . credentials ) {
128
125
return this . credentials ! ;
129
126
}
130
127
131
- // Check if existing stored token is still valid
132
- if ( this . credentials ?. token ) {
133
- const { exp } = this . parseToken ( this . credentials ?. token ) ?? { } ;
134
-
135
- if ( exp && new Date ( Number ( exp ) * 1000 ) > currentTime ) {
136
- return this . credentials ! ;
137
- }
138
- }
139
-
140
128
this . credentials = await this . connector . fetchCredentials ( ) ;
141
129
if ( this . credentials ?. endpoint . match ( POWERSYNC_TRAILING_SLASH_MATCH ) ) {
142
130
throw new Error (
@@ -150,14 +138,6 @@ export abstract class AbstractRemote {
150
138
return `powersync-js/${ POWERSYNC_JS_VERSION } ` ;
151
139
}
152
140
153
- private parseToken ( token : string ) {
154
- try {
155
- return JSON . parse ( Buffer . from ( token . split ( '.' ) [ 1 ] , 'base64' ) . toString ( ) ) ;
156
- } catch ( _ ) {
157
- return null ;
158
- }
159
- }
160
-
161
141
protected async buildRequest ( path : string ) {
162
142
const credentials = await this . getCredentials ( ) ;
163
143
if ( credentials != null && ( credentials . endpoint == null || credentials . endpoint == '' ) ) {
0 commit comments