Skip to content

Commit

Permalink
Display warning when accessing API page with no credentials;
Browse files Browse the repository at this point in the history
  • Loading branch information
Leandro Diato committed Oct 13, 2021
1 parent 19daa51 commit 33151f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
16 changes: 5 additions & 11 deletions dev-portal/src/components/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import {
isAuthenticated,
isRegistered,
logout,
getLoginRedirectUrl
getCognitoUrl
} from 'services/self'

import { cognitoDomain, cognitoClientId } from '../services/api'

// mobx
import { observer } from 'mobx-react'

Expand All @@ -24,14 +22,10 @@ import { fragments } from 'services/get-fragments'
import MenuLink from 'components/MenuLink'
import { store } from 'services/state'

function getCognitoUrl (type) {
const redirectUri = getLoginRedirectUrl()
return `${cognitoDomain}/${type}?response_type=token&client_id=${cognitoClientId}&redirect_uri=${redirectUri}`
}

export const NavBar = observer(
class NavBar extends React.Component {
render () {
render() {
const email = store.user && store.user.email
return <Menu inverted borderless attached style={{ flex: '0 0 auto' }} stackable>
<MenuLink to='/'>
Expand All @@ -57,9 +51,9 @@ export const NavBar = observer(
</div>
</MenuLink>
</> : <>
<MenuLink to={getCognitoUrl('login')}>Sign In</MenuLink>
<MenuLink to={getCognitoUrl('signup')}>Register</MenuLink>
</>}
<MenuLink to={getCognitoUrl('login')}>Sign In</MenuLink>
<MenuLink to={getCognitoUrl('signup')}>Register</MenuLink>
</>}
</Menu.Menu>
</Menu>
}
Expand Down
30 changes: 23 additions & 7 deletions dev-portal/src/pages/Apis.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import SwaggerUI from 'swagger-ui'
import 'swagger-ui/dist/swagger-ui.css'

// semantic-ui
import { Container, Header, Icon } from 'semantic-ui-react'
import { Segment, Button, Container, Header, Icon } from 'semantic-ui-react'

// services
import { isRegistered } from 'services/self'
import { isRegistered, getCognitoUrl } from 'services/self'
import { updateUsagePlansAndApisList, getApi } from 'services/api-catalog'

// components
Expand All @@ -27,11 +27,11 @@ export default observer(class ApisPage extends React.Component {
containerRef = React.createRef()
hasRoot = false

componentDidMount () { this.updateApi(true) }
componentDidUpdate () { this.updateApi(false) }
componentWillUnmount () { this.containerRef = null }
componentDidMount() { this.updateApi(true) }
componentDidUpdate() { this.updateApi(false) }
componentWillUnmount() { this.containerRef = null }

updateApi (isInitial) {
updateApi(isInitial) {
return getApi(this.props.match.params.apiId || 'ANY', true, this.props.match.params.stage, isInitial)
.then(api => {
if (this.containerRef == null) return
Expand Down Expand Up @@ -72,10 +72,26 @@ export default observer(class ApisPage extends React.Component {
})
}

render () {
signIn() {
window.location = getCognitoUrl('login');
}

render() {
let errorHeader
let errorBody

if (!store.apiKey) {
return (
<Segment placeholder style={{ margin: '5em' }}>
<Header icon>
<Icon name='sign-in' />
Please sign-in to access the available APIs
</Header>
<Button positive onClick={this.signIn}>Sign In</Button>
</Segment>
)
}

if (store.apiList.loaded) {
if (!store.apiList.apiGateway.length && !store.apiList.generic.length) {
errorHeader = 'No APIs Published'
Expand Down
5 changes: 5 additions & 0 deletions dev-portal/src/services/self.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,8 @@ export function logout () {
}
}
}

export function getCognitoUrl(type) {
const redirectUri = getLoginRedirectUrl()
return `${cognitoDomain}/${type}?response_type=token&client_id=${cognitoClientId}&redirect_uri=${redirectUri}`
}

0 comments on commit 33151f8

Please sign in to comment.