Skip to content

Commit 4aa9c69

Browse files
committed
Provides a page for when user is not signed in
1 parent f37d6dc commit 4aa9c69

File tree

3 files changed

+49
-37
lines changed

3 files changed

+49
-37
lines changed

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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 onClick={() => signIn('osm-teams')}>Sign in →</Button>
22+
<Text>Still having problems? Contact a system administrator.</Text>
23+
</Box>
24+
</Container>
25+
</Box>
26+
</>
27+
)
28+
}
29+
30+
export async function getServerSideProps(context) {
31+
const session = await getServerSession(context.req, context.res, authOptions)
32+
33+
// If the user is already logged in, redirect.
34+
// Note: Make sure not to redirect to the same page
35+
// To avoid an infinite loop!
36+
if (session) {
37+
return { redirect: { destination: '/' } }
38+
}
39+
40+
const providers = await getProviders()
41+
42+
return {
43+
props: { providers: providers ?? [] },
44+
}
45+
}

0 commit comments

Comments
 (0)