Skip to content

Commit 7e17b4e

Browse files
authored
Merge pull request #451 from developmentseed/fix/not-signed-in
Provides a page for when user is not signed in
2 parents f37d6dc + e7874cf commit 7e17b4e

File tree

5 files changed

+54
-40
lines changed

5 files changed

+54
-40
lines changed

cypress/e2e/auth.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Check protected routes', () => {
2121
protectedRoutes.forEach((testRoute) => {
2222
it(`Route ${testRoute} needs authentication`, () => {
2323
cy.visit(testRoute)
24-
cy.get('body').should('contain', 'Sign in with OSM Teams')
24+
cy.get('body').should('contain', 'Sign in')
2525
})
2626
})
2727

cypress/e2e/organizations/permissions.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('Organizations page: Permissions', () => {
6767
it('Org is private', () => {
6868
// Unauthenticated user cannot access
6969
cy.visit('/organizations/1')
70-
cy.get('body').should('contain', 'Sign in with OSM Teams')
70+
cy.get('body').should('contain', 'Sign in')
7171

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

143143
// Unauthenticated can view org
144144
cy.visit('/organizations/2')
145-
cy.get('body').should('contain', 'Sign in with OSM Teams')
145+
cy.get('body').should('contain', 'Sign in')
146146

147147
// Non-member can access, but cannot view private teams
148148
cy.login(nonMember)

src/pages/api/auth/[...nextauth].js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export const authOptions = {
4040
},
4141
},
4242

43+
pages: {
44+
signIn: '/signin',
45+
},
46+
4347
events: {
4448
async signIn({ profile }) {
4549
// On successful sign in we should persist the user to the database

src/pages/login.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/pages/signin.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { signIn, getProviders } from 'next-auth/react'
2+
import { getServerSession } from 'next-auth/next'
3+
import { Box, Container, Heading, Text, Button } from '@chakra-ui/react'
4+
import InpageHeader from '../components/inpage-header'
5+
import { authOptions } from './api/auth/[...nextauth]'
6+
7+
export default function SignIn() {
8+
return (
9+
<>
10+
<Box as='main' mb={8}>
11+
<InpageHeader>
12+
<Heading color='white' mb={2}>
13+
You are not signed in.
14+
</Heading>
15+
</InpageHeader>
16+
<Container maxW='container.xl' as='section'>
17+
<Box layerStyle={'shadowed'}>
18+
<Text fontSize='2xl'>
19+
Sorry, you need to be signed in to view this page.
20+
</Text>
21+
<Button my={4} onClick={() => signIn('osm-teams')}>
22+
Sign in →
23+
</Button>
24+
<Text>Still having problems? Contact a system administrator.</Text>
25+
</Box>
26+
</Container>
27+
</Box>
28+
</>
29+
)
30+
}
31+
32+
export async function getServerSideProps(context) {
33+
const session = await getServerSession(context.req, context.res, authOptions)
34+
35+
// If the user is already logged in, redirect.
36+
// Note: Make sure not to redirect to the same page
37+
// To avoid an infinite loop!
38+
if (session) {
39+
return { redirect: { destination: '/' } }
40+
}
41+
42+
const providers = await getProviders()
43+
44+
return {
45+
props: { providers: providers ?? [] },
46+
}
47+
}

0 commit comments

Comments
 (0)