Skip to content

Commit 33151f8

Browse files
author
Leandro Diato
committed
Display warning when accessing API page with no credentials;
1 parent 19daa51 commit 33151f8

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

dev-portal/src/components/NavBar.jsx

+5-11
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import {
99
isAuthenticated,
1010
isRegistered,
1111
logout,
12-
getLoginRedirectUrl
12+
getCognitoUrl
1313
} from 'services/self'
1414

15-
import { cognitoDomain, cognitoClientId } from '../services/api'
16-
1715
// mobx
1816
import { observer } from 'mobx-react'
1917

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

27-
function getCognitoUrl (type) {
28-
const redirectUri = getLoginRedirectUrl()
29-
return `${cognitoDomain}/${type}?response_type=token&client_id=${cognitoClientId}&redirect_uri=${redirectUri}`
30-
}
3125

3226
export const NavBar = observer(
3327
class NavBar extends React.Component {
34-
render () {
28+
render() {
3529
const email = store.user && store.user.email
3630
return <Menu inverted borderless attached style={{ flex: '0 0 auto' }} stackable>
3731
<MenuLink to='/'>
@@ -57,9 +51,9 @@ export const NavBar = observer(
5751
</div>
5852
</MenuLink>
5953
</> : <>
60-
<MenuLink to={getCognitoUrl('login')}>Sign In</MenuLink>
61-
<MenuLink to={getCognitoUrl('signup')}>Register</MenuLink>
62-
</>}
54+
<MenuLink to={getCognitoUrl('login')}>Sign In</MenuLink>
55+
<MenuLink to={getCognitoUrl('signup')}>Register</MenuLink>
56+
</>}
6357
</Menu.Menu>
6458
</Menu>
6559
}

dev-portal/src/pages/Apis.jsx

+23-7
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import SwaggerUI from 'swagger-ui'
88
import 'swagger-ui/dist/swagger-ui.css'
99

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

1313
// services
14-
import { isRegistered } from 'services/self'
14+
import { isRegistered, getCognitoUrl } from 'services/self'
1515
import { updateUsagePlansAndApisList, getApi } from 'services/api-catalog'
1616

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

30-
componentDidMount () { this.updateApi(true) }
31-
componentDidUpdate () { this.updateApi(false) }
32-
componentWillUnmount () { this.containerRef = null }
30+
componentDidMount() { this.updateApi(true) }
31+
componentDidUpdate() { this.updateApi(false) }
32+
componentWillUnmount() { this.containerRef = null }
3333

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

75-
render () {
75+
signIn() {
76+
window.location = getCognitoUrl('login');
77+
}
78+
79+
render() {
7680
let errorHeader
7781
let errorBody
7882

83+
if (!store.apiKey) {
84+
return (
85+
<Segment placeholder style={{ margin: '5em' }}>
86+
<Header icon>
87+
<Icon name='sign-in' />
88+
Please sign-in to access the available APIs
89+
</Header>
90+
<Button positive onClick={this.signIn}>Sign In</Button>
91+
</Segment>
92+
)
93+
}
94+
7995
if (store.apiList.loaded) {
8096
if (!store.apiList.apiGateway.length && !store.apiList.generic.length) {
8197
errorHeader = 'No APIs Published'

dev-portal/src/services/self.js

+5
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,8 @@ export function logout () {
155155
}
156156
}
157157
}
158+
159+
export function getCognitoUrl(type) {
160+
const redirectUri = getLoginRedirectUrl()
161+
return `${cognitoDomain}/${type}?response_type=token&client_id=${cognitoClientId}&redirect_uri=${redirectUri}`
162+
}

0 commit comments

Comments
 (0)