Skip to content

Commit

Permalink
Provides a page for when user is not signed in
Browse files Browse the repository at this point in the history
  • Loading branch information
kamicut committed Jun 7, 2023
1 parent f37d6dc commit 4aa9c69
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 37 deletions.
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.

45 changes: 45 additions & 0 deletions src/pages/signin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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 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 4aa9c69

Please sign in to comment.