Skip to content

Commit

Permalink
Send users to account connect page if unauthorized
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda committed Nov 6, 2024
1 parent 7a88e81 commit d5e2d00
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
5 changes: 3 additions & 2 deletions app/guid-node/addons/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
/>
{{#if account.displayName}}
{{account.displayName}}
{{else if (not account.credentialsAvailable)}}
{{t 'addons.accountSelect.unauthenticated-account'}}
{{else}}
{{t 'addons.accountSelect.unnamed-account'}}
{{/if}}
</label>
</div>
Expand Down Expand Up @@ -128,6 +128,7 @@
<AddonsService::AddonAccountSetup
@provider={{provider.provider}}
@manager={{manager}}
@account={{manager.selectedAccount}}
@onConnect={{manager.connectAccount}}
/>
{{else if (eq manager.pageMode 'confirm')}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ export default class AddonAccountSetupComponent extends Component<Args> {
@task
@waitFor
async checkOauthSuccess() {
const oauthSuccesful = await taskFor(this.args.manager.oauthFlowRefocus).perform(this.newAccount!);
const accountToCheck = this.args.account || this.newAccount;
const oauthSuccesful = await taskFor(this.args.manager.oauthFlowRefocus).perform(accountToCheck!);
if (oauthSuccesful) {
this.pendingOauth = false;
document.removeEventListener('visibilitychange', this.onVisibilityChange);
Expand Down Expand Up @@ -267,17 +268,16 @@ export default class AddonAccountSetupComponent extends Component<Args> {
async startOauthReconnectFlow() {
const { account } = this.args;
if (account) {
account.initiateOauth = true;
account.displayName = this.displayName;
await account.save(); // returned account should have authUrl
if (!account.authUrl) {
account.initiateOauth = true;
account.displayName = this.displayName;
await account.save(); // returned account should have authUrl
}

if (account.authUrl) {
const oauthWindow = window.open(account.authUrl, '_blank');
if (oauthWindow) {
document.addEventListener('visibilitychange', this.onVisibilityChange);
this.pendingOauth = true;
} else {
this.toast.error(this.intl.t('addons.accountCreate.oauth-window-blocked'));
}
this.pendingOauth = true;
window.open(account.authUrl, '_blank');
document.addEventListener('visibilitychange', this.onVisibilityChange);
} else {
this.toast.error(this.intl.t('addons.accountCreate.oauth-reconnect-error'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
data-test-start-oauth-button
data-analytics-name='Start OAuth'
@target='_blank'
@href={{this.newAccount.authUrl}}
@href={{if @account @account.authUrl this.newAccount.authUrl}}
>
{{t 'addons.accountCreate.oauth-start'}}
</OsfLink>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ export default class AddonsServiceManagerComponent extends Component<Args> {

@action
authorizeSelectedAccount() {
this.pageMode = PageMode.CONFIRM;
if (this.selectedAccount && this.selectedAccount.credentialsAvailable) {
this.pageMode = PageMode.CONFIRM;
} else {
this.pageMode = PageMode.ACCOUNT_CREATE;
}
}

@task
Expand Down
2 changes: 1 addition & 1 deletion translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ addons:
new-account: 'Setup new account'
reconnect-account: 'Reconnect account'
existing-account: 'Choose existing account'
unauthenticated-account: 'Unconnected account'
unnamed-account: 'Unnamed account'
accountCreate:
display-name-label: 'Display name'
display-name-placeholder: 'Account name'
Expand Down

0 comments on commit d5e2d00

Please sign in to comment.