Skip to content

Commit

Permalink
[dashboard] Accelerate authorization redirect in create workspace page
Browse files Browse the repository at this point in the history
  • Loading branch information
jankeromnes committed Apr 7, 2021
1 parent d090d2c commit b0803d4
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions components/dashboard/src/start/CreateWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,8 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
</div>;
break;
case ErrorCodes.NOT_AUTHENTICATED:
const authorizeUrl = gitpodHostUrl.withApi({
pathname: '/authorize',
search: `returnTo=${encodeURIComponent(window.location.toString())}&host=${error.data.host}&scopes=${error.data.scopes.join(',')}`
}).toString();
window.location.href = authorizeUrl;
statusMessage = <div className="mt-2 flex flex-col space-y-8">
<p className="text-base w-96">Redirecting to authorize with {error.data.host}</p>
<a href={authorizeUrl}><button className="secondary">Authorize with {error.data.host}</button></a>
</div>;
break;
const authorizeURL = `/api/authorize?returnTo=${encodeURIComponent(window.location.toString())}&host=${error.data.host}&scopes=${error.data.scopes.join(',')}`;
return <Redirect push to={authorizeURL}/>;
case ErrorCodes.USER_BLOCKED:
return <Redirect to="/blocked"/>;
case ErrorCodes.NOT_FOUND:
Expand Down Expand Up @@ -206,12 +198,6 @@ function RepositoryNotFoundView(p: { error: StartWorkspaceError }) {
(async () => {
const service = getGitpodService();
const { host, owner, repoName, userIsOwner, userScopes, lastUpdate } = p.error.data;
console.log('host', host);
console.log('owner', owner);
console.log('repoName', repoName);
console.log('userIsOwner', userIsOwner);
console.log('userScopes', userScopes);
console.log('lastUpdate', lastUpdate);

if ((await service.server.mayAccessPrivateRepo()) === false) {
setStatusMessage(<LimitReachedPrivateRepoModal/>);
Expand All @@ -227,10 +213,7 @@ function RepositoryNotFoundView(p: { error: StartWorkspaceError }) {

// TODO: this should be aware of already granted permissions
const missingScope = authProvider.host === 'github.com' ? 'repo' : 'read_repository';
const authorizeURL = gitpodHostUrl.withApi({
pathname: '/authorize',
search: `returnTo=${encodeURIComponent(window.location.toString())}&host=${host}&scopes=${missingScope}`
}).toString();
const authorizeURL = `/api/authorize?returnTo=${encodeURIComponent(window.location.toString())}&host=${host}&scopes=${missingScope}`;

if (!userScopes.includes(missingScope)) {
setStatusMessage(<div className="mt-2 flex flex-col space-y-8">
Expand Down

0 comments on commit b0803d4

Please sign in to comment.