Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Commit

Permalink
Fix for email authentication and error handling
Browse files Browse the repository at this point in the history
Fixing bug with email link page introduced in 4.5.0 and improving new error page formatting.
  • Loading branch information
iaincollins committed Jan 27, 2018
1 parent b276629 commit cadc19c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "nextjs-starter",
"version": "4.5.2",
"version": "4.5.3",
"description": "A starter Next.js project with email and oAuth authentication",
"author": "Iain Collins <me@iaincollins.com>",
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion pages/auth/check-email.js
Expand Up @@ -12,7 +12,7 @@ export default class extends Page {

// If signed in already, instead of displaying message send to callback page
// which should redirect them to whatever page it normally sends clients to
if (session.user) {
if (props.session.user) {
if (req) {
res.redirect('/auth/callback')
} else {
Expand Down
38 changes: 15 additions & 23 deletions pages/auth/error.js
@@ -1,24 +1,22 @@
import React from 'react'
import Head from 'next/head'
import Link from 'next/link'
import Page from '../../components/page'
import Layout from '../../components/layout'

export default class extends React.Component {
export default class extends Page {

static async getInitialProps({query}) {
return {
action: query.action || null,
type: query.type || null,
service: query.service || null
}
static async getInitialProps({req, query}) {
let props = await super.getInitialProps({req})
props.action = query.action || null
props.type = query.type || null
props.service = query.service || null
return props
}

render() {
if (this.props.action == 'signin' && this.props.type == 'oauth' && this.props.service) {
return(
<div className="container">
<Head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossOrigin="anonymous"/>
</Head>
<Layout {...this.props} navmenu={false}>
<div className="text-center">
<h1 className="display-4 mt-5 mb-3">Unable to sign in with {this.props.service}</h1>
<p className="lead">An account associated with your email address already exists.</p>
Expand All @@ -39,35 +37,29 @@ export default class extends React.Component {
</div>
</div>
</div>
</div>
</Layout>
)
} else if (this.props.action == 'signin' && this.props.type == 'token-invalid') {
return(
<div className="container">
<Head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossOrigin="anonymous"/>
</Head>
<Layout {...this.props} navmenu={false}>
<div className="text-center">
<h1 className="display-4 mt-5 mb-2">Sign in link not valid</h1>
<p className="lead">The sign in link you used is no longer valid.</p>
<p className="lead"><Link href="/auth"><a>Get a new sign in link.</a></Link></p>
</div>
</div>
</Layout>
)
} else {
return(
<div className="container">
<Head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossOrigin="anonymous"/>
</Head>
<Layout {...this.props} navmenu={false}>
<div className="text-center">
<h1 className="display-4 mt-5">Error signing in</h1>
<p className="lead">An error occured while trying to sign in.</p>
<p>
<Link href="/"><a>Home</a></Link>
</p>
</div>
</div>
</Layout>
)
}
}
Expand Down

0 comments on commit cadc19c

Please sign in to comment.