MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / ensureAuthenticated

Method ensureAuthenticated

console/e2e-tests/util.ts:192–228  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

190 }
191
192 async ensureAuthenticated() {
193 if (new Date().getTime() < this.refreshDeadline.getTime()) {
194 return;
195 }
196
197 const authUrl = buildFronteggUrl("/identity/resources/auth/v1/user");
198 const response = await retry(
199 () =>
200 this.request.post(authUrl, {
201 data: {
202 email: EMAIL,
203 password: PASSWORD,
204 },
205 timeout: 10 * 1000,
206 }),
207 // Sometimes we get ECONNRESET or requests hang on these frontegg calls
208 { retries: 4 },
209 );
210
211 const text = await response.text();
212 let auth: FronteggAuthResponse;
213 try {
214 auth = JSON.parse(text);
215 } catch (e: unknown) {
216 console.error(`Invalid json from ${authUrl}:\n${text}`);
217 throw e as SyntaxError;
218 }
219
220 this.accessToken = auth.accessToken;
221 this.refreshToken = auth.refreshToken;
222 // Use the expiresIn instead of expires, since expires is a hard to work
223 // with string.
224 this.refreshDeadline = new Date();
225 this.refreshDeadline.setUTCSeconds(
226 this.refreshDeadline.getUTCSeconds() + auth.expiresIn / 2,
227 );
228 }
229
230 /**
231 * Because frontegg is really slow, we explicitly wait to see our page layout, which

Callers 2

apiRequestMethod · 0.95
disableRegionMethod · 0.95

Calls 4

buildFronteggUrlFunction · 0.90
retryFunction · 0.50
parseMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected