diff --git a/cypress/e2e/auth.cy.js b/cypress/e2e/auth.cy.js
index 3b1cf6cb..57290eaf 100644
--- a/cypress/e2e/auth.cy.js
+++ b/cypress/e2e/auth.cy.js
@@ -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')
})
})
diff --git a/cypress/e2e/organizations/permissions.cy.js b/cypress/e2e/organizations/permissions.cy.js
index dca3237a..ec3f5d1f 100644
--- a/cypress/e2e/organizations/permissions.cy.js
+++ b/cypress/e2e/organizations/permissions.cy.js
@@ -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)
@@ -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)
diff --git a/src/pages/api/auth/[...nextauth].js b/src/pages/api/auth/[...nextauth].js
index 519bda6e..34c2175e 100644
--- a/src/pages/api/auth/[...nextauth].js
+++ b/src/pages/api/auth/[...nextauth].js
@@ -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
diff --git a/src/pages/login.js b/src/pages/login.js
deleted file mode 100644
index 16b6a553..00000000
--- a/src/pages/login.js
+++ /dev/null
@@ -1,37 +0,0 @@
-import React, { Component } from 'react'
-import { Box, Button, Container, Heading } from '@chakra-ui/react'
-import Link from 'next/link'
-
-const OSM_NAME = process.env.OSM_NAME
-class Login extends Component {
- static async getInitialProps({ query }) {
- if (query) {
- return {
- challenge: query.challenge,
- }
- }
- }
-
- render() {
- return (
-
-
- Login
-
- Teams uses {OSM_NAME} as your login, connect your {OSM_NAME}{' '}
- account!
-
-
-
-
-
- )
- }
-}
-
-export default Login
diff --git a/src/pages/signin.js b/src/pages/signin.js
new file mode 100644
index 00000000..9995e1f2
--- /dev/null
+++ b/src/pages/signin.js
@@ -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 (
+ <>
+
+
+
+ You are not signed in.
+
+
+
+
+
+ Sorry, you need to be signed in to view this page.
+
+
+ Still having problems? Contact a system administrator.
+
+
+
+ >
+ )
+}
+
+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 ?? [] },
+ }
+}