Skip to content

Display warning when accessing API page with no credentials; #453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 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,10 +22,6 @@ 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 {
Expand Down
20 changes: 18 additions & 2 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 Down Expand Up @@ -72,10 +72,26 @@ export default observer(class ApisPage extends React.Component {
})
}

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}`
}