Skip to content

Commit

Permalink
Merge pull request #451 from developmentseed/fix/not-signed-in
Browse files Browse the repository at this point in the history
Provides a page for when user is not signed in
  • Loading branch information
kamicut authored Jun 9, 2023
2 parents f37d6dc + e7874cf commit 7e17b4e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 40 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/auth.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Check protected routes', () => {
protectedRoutes.forEach((testRoute) => {
it(`Route ${testRoute} needs authentication`, () => {
cy.visit(testRoute)
cy.get('body').should('contain', 'Sign in with OSM Teams')
cy.get('body').should('contain', 'Sign in')
})
})

Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/organizations/permissions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Organizations page: Permissions', () => {
it('Org is private', () => {
// Unauthenticated user cannot access
cy.visit('/organizations/1')
cy.get('body').should('contain', 'Sign in with OSM Teams')
cy.get('body').should('contain', 'Sign in')

// Non-member cannot access
cy.login(nonMember)
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('Organizations page: Permissions', () => {

// Unauthenticated can view org
cy.visit('/organizations/2')
cy.get('body').should('contain', 'Sign in with OSM Teams')
cy.get('body').should('contain', 'Sign in')

// Non-member can access, but cannot view private teams
cy.login(nonMember)
Expand Down
4 changes: 4 additions & 0 deletions src/pages/api/auth/[...nextauth].js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export const authOptions = {
},
},

pages: {
signIn: '/signin',
},

events: {
async signIn({ profile }) {
// On successful sign in we should persist the user to the database
Expand Down
37 changes: 0 additions & 37 deletions src/pages/login.js

This file was deleted.

47 changes: 47 additions & 0 deletions src/pages/signin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { signIn, getProviders } from 'next-auth/react'
import { getServerSession } from 'next-auth/next'
import { Box, Container, Heading, Text, Button } from '@chakra-ui/react'
import InpageHeader from '../components/inpage-header'
import { authOptions } from './api/auth/[...nextauth]'

export default function SignIn() {
return (
<>
<Box as='main' mb={8}>
<InpageHeader>
<Heading color='white' mb={2}>
You are not signed in.
</Heading>
</InpageHeader>
<Container maxW='container.xl' as='section'>
<Box layerStyle={'shadowed'}>
<Text fontSize='2xl'>
Sorry, you need to be signed in to view this page.
</Text>
<Button my={4} onClick={() => signIn('osm-teams')}>
Sign in →
</Button>
<Text>Still having problems? Contact a system administrator.</Text>
</Box>
</Container>
</Box>
</>
)
}

export async function getServerSideProps(context) {
const session = await getServerSession(context.req, context.res, authOptions)

// If the user is already logged in, redirect.
// Note: Make sure not to redirect to the same page
// To avoid an infinite loop!
if (session) {
return { redirect: { destination: '/' } }
}

const providers = await getProviders()

return {
props: { providers: providers ?? [] },
}
}

0 comments on commit 7e17b4e

Please sign in to comment.