-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from dekart-xyz/delay-scope-request
Delay scope request
- Loading branch information
Showing
24 changed files
with
890 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE IF NOT EXISTS users ( | ||
email varchar(255) PRIMARY KEY, | ||
sensitive_scope TEXT default '', -- requested before sensitive scope | ||
created_at timestamptz DEFAULT CURRENT_TIMESTAMP, | ||
updated_at timestamptz DEFAULT CURRENT_TIMESTAMP | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Header } from './Header' | ||
import styles from './GrantScopesPage.module.css' | ||
import Result from 'antd/es/result' | ||
import Button from 'antd/es/button' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import { requestSensitiveScopes } from './actions/redirect' | ||
import { CloudTwoTone } from '@ant-design/icons' | ||
import { useEffect } from 'react' | ||
import { Redirect } from 'react-router-dom/cjs/react-router-dom' | ||
|
||
function getLastPage (visitedPages) { | ||
return visitedPages.current.filter(page => page !== '/grant-scopes').pop() | ||
} | ||
|
||
export default function GrantScopesPage ({ visitedPages }) { | ||
const dispatch = useDispatch() | ||
const userStream = useSelector(state => state.user.stream) | ||
const sensitiveScopesGrantedOnce = useSelector(state => state.user.sensitiveScopesGrantedOnce) | ||
|
||
useEffect(() => { | ||
if ( | ||
!userStream || // userStream is not yet loaded | ||
userStream.sensitiveScopesGranted // user has already granted sensitive scopes | ||
) { | ||
return | ||
} | ||
if (sensitiveScopesGrantedOnce) { // user has granted sensitive scopes once, request them right away without onboarding | ||
dispatch(requestSensitiveScopes(getLastPage(visitedPages))) | ||
} | ||
} | ||
, [dispatch, userStream, visitedPages, sensitiveScopesGrantedOnce]) | ||
|
||
if (!userStream) { | ||
return null | ||
} | ||
|
||
if (userStream.sensitiveScopesGranted) { | ||
// user shouldn't be here | ||
return <Redirect to='/' push /> | ||
} | ||
|
||
if (sensitiveScopesGrantedOnce) { | ||
// user will be automatically redirected to the auth page in useEffect above | ||
return null | ||
} | ||
|
||
return ( | ||
<div className={styles.grantScopesPage}> | ||
<Header /> | ||
<div className={styles.body}> | ||
<Result | ||
icon={<CloudTwoTone />} | ||
title='Grant access to Google Cloud' | ||
subTitle={<>Dekart needs access to your <b>BigQuery</b> and <b>Google Cloud Storage</b> to query and store results.<br /> Your token is not stored in Dekart. You can revoke access by signing out of Dekart anytime.</>} | ||
extra={( | ||
<Button | ||
type='primary' onClick={() => { | ||
dispatch(requestSensitiveScopes(getLastPage(visitedPages))) | ||
}} | ||
>Continue to Google | ||
</Button> | ||
)} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.grantScopesPage { | ||
width: 100%; | ||
height: 100%; | ||
position: absolute; | ||
background-color: #F7F7F7; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.body { | ||
padding: 20px; | ||
display: flex; | ||
flex: 1; | ||
overflow: scroll; | ||
align-items: center; | ||
flex-direction: column; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
const LOCAL_STORAGE_KEY = 'dekart-local-storage-v1' | ||
|
||
const initialState = { | ||
sensitiveScopesGrantedOnce: false | ||
} | ||
|
||
let current = initialState | ||
|
||
export function localStorageInit () { | ||
return { | ||
type: localStorageInit.name, | ||
current | ||
} | ||
} | ||
|
||
export function updateLocalStorage (key, value) { | ||
current[key] = value | ||
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(current)) | ||
return { | ||
type: updateLocalStorage.name, | ||
current | ||
} | ||
} | ||
|
||
export function loadLocalStorage () { | ||
return (dispatch) => { | ||
const localStorageValue = window.localStorage.getItem(LOCAL_STORAGE_KEY) | ||
if (localStorageValue) { | ||
current = JSON.parse(localStorageValue) | ||
dispatch(localStorageInit()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.