Skip to content

Commit

Permalink
Fixing an issue where old access_tokens would be used intead of reque…
Browse files Browse the repository at this point in the history
…sting new ones (#7433)
  • Loading branch information
joehan authored Jul 11, 2024
1 parent 743e8a8 commit c6622ca
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,10 @@ export function getAllAccounts(): Account[] {
* @param options options object.
* @param account account to make active.
*/
export function setActiveAccount(options: any, account: Account) {
export async function setActiveAccount(options: any, account: Account) {
if (account.tokens.refresh_token) {
setRefreshToken(account.tokens.refresh_token);
}

if (account.tokens.access_token) {
setAccessToken(account.tokens.access_token);
setAccessToken(await apiv2.getAccessToken());
}

options.user = account.user;
Expand Down
2 changes: 1 addition & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export class Command {
const activeAccount = selectAccount(account, projectRoot);

if (activeAccount) {
setActiveAccount(options, activeAccount);
await setActiveAccount(options, activeAccount);
}

this.applyRC(options);
Expand Down
2 changes: 1 addition & 1 deletion src/init/features/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function doSetup(setup: any, config: any, options: any): Promise<vo
}

// Set the global auth state
setActiveAccount(options, account);
await setActiveAccount(options, account);

// Set the project default user
if (config.projectDir) {
Expand Down
7 changes: 5 additions & 2 deletions src/requireAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ async function autoAuth(options: Options, authScopes: string[]): Promise<void |
}
if (process.env.MONOSPACE_ENV && token && clientEmail) {
// Within monospace, this a OAuth token for the user, so we make it the active user.
setActiveAccount(options, { user: { email: clientEmail }, tokens: { access_token: token } });
await setActiveAccount(options, {
user: { email: clientEmail },
tokens: { access_token: token },
});
setGlobalDefaultAccount({ user: { email: clientEmail }, tokens: { access_token: token } });

// project is also selected in monospace auth flow
Expand Down Expand Up @@ -107,6 +110,6 @@ export async function requireAuth(options: any): Promise<string | void> {
throw new FirebaseError(AUTH_ERROR_MESSAGE);
}

setActiveAccount(options, { user, tokens });
await setActiveAccount(options, { user, tokens });
return user.email;
}

0 comments on commit c6622ca

Please sign in to comment.