Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
fixup! Revert "Do not store state of Welcome page (#848)" (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Sep 23, 2020
1 parent 9cc1fd4 commit 4da64b9
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions plugins/github-auth-plugin/src/github-auth-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ import * as theia from '@theia/plugin';
import * as che from '@eclipse-che/plugin';

export async function start(context: theia.PluginContext): Promise<void> {
let session: theia.AuthenticationSession | undefined = context.workspaceState.get('session');
if (theia.plugins.getPlugin('github.vscode-pull-request-github')) {
let session: theia.AuthenticationSession | undefined = context.workspaceState.get('session');
const onDidChangeSessions = new theia.EventEmitter<theia.AuthenticationProviderAuthenticationSessionsChangeEvent>();
theia.authentication.onDidChangeSessions(async () => {
await theia.authentication.getSession('github', ['read:user', 'user:email', 'repo']);
});
theia.authentication.registerAuthenticationProvider({
id: 'github',
label: 'GitHub',
Expand All @@ -30,24 +27,38 @@ export async function start(context: theia.PluginContext): Promise<void> {
return [];
}
},
login: async (scopeList: string[]) => {
login: async (scopes: string[]) => {
const githubUser = await che.github.getUser();
session = {
id: 'github-session',
accessToken: await che.github.getToken(),
account: {label: githubUser.login, id: githubUser.id.toString()},
scopes: scopeList
scopes
};
context.workspaceState.update('session', session);
onDidChangeSessions.fire({added: [session.id], removed: [], changed: []});
onDidChangeSessions.fire({ added: [session.id], removed: [], changed: [] });
return session;
},
logout: async (id: string) => {
session = undefined;
onDidChangeSessions.fire({added: [], removed: [id], changed: []});
context.workspaceState.update('session', session);
onDidChangeSessions.fire({ added: [], removed: [id], changed: [] });
}
}
);
if (session) {
onDidChangeSessions.fire({ added: [session.id], removed: [], changed: [] });
// TODO Remove the notification when https://github.com/eclipse-theia/theia/issues/7178 is fixed.
} else {
const signIn = 'Sign in';
const result = await theia.window.showInformationMessage(
'In order to use the Pull Requests functionality, you must sign in to GitHub',
signIn);

if (result === signIn) {
theia.authentication.getSession('github', ['read:user', 'user:email', 'repo'], { createIfNone: true });
}
}
}
}

Expand Down

0 comments on commit 4da64b9

Please sign in to comment.