Skip to content

Commit

Permalink
Export to manifest on get
Browse files Browse the repository at this point in the history
Summary:
Every time the token is returned, export it to the manifest.

This covers the case in which the token found in the manifest has already expired.

Reviewed By: antonk52

Differential Revision: D50419458

fbshipit-source-id: 8eefa0e97e234985b34f824190b208bf74e2d8ec
  • Loading branch information
lblasa authored and facebook-github-bot committed Oct 18, 2023
1 parent 82f0c0e commit f6de499
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,18 @@ export const generateAuthToken = async () => {
return token;
};

/**
* Gets the client authentication token. If there is no existing token,
* it generates one, export it to the manifest file and returns it.
*
* Additionally, it must check the token's validity before returning it.
* If the token is invalid, it regenerates it and exports it to the manifest file.
*
* Finally, the token is also exported to the manifest, on every get as to
* ensure it is always up to date.
*
* @returns
*/
export const getAuthToken = async (): Promise<string> => {
if (!(await hasAuthToken())) {
return generateAuthToken();
Expand All @@ -349,6 +361,12 @@ export const getAuthToken = async (): Promise<string> => {
return generateAuthToken();
}

const config = getFlipperServerConfig();
if (config.environmentInfo.isHeadlessBuild) {
console.info('Token exported to manifest');
await exportTokenToManifest(config, token.toString());
}

return token.toString();
};

Expand Down

0 comments on commit f6de499

Please sign in to comment.