Skip to content
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

Provides a page for when user is not signed in #451

Merged
merged 3 commits into from
Jun 9, 2023
Merged
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
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 ?? [] },
}
}