|
1 | 1 | import { signIn } from 'next-auth/react'
|
2 | 2 | import styles from './login.module.css'
|
3 | 3 | import { Form, Input, SubmitButton } from '@/components/form'
|
4 |
| -import { useState } from 'react' |
| 4 | +import { useState, useEffect } from 'react' |
5 | 5 | import Alert from 'react-bootstrap/Alert'
|
6 | 6 | import { useRouter } from 'next/router'
|
7 | 7 | import { LightningAuthWithExplainer } from './lightning-auth'
|
@@ -42,21 +42,34 @@ const authErrorMessages = {
|
42 | 42 | OAuthCallback: 'Error handling OAuth response. Try again or choose a different method.',
|
43 | 43 | OAuthCreateAccount: 'Could not create OAuth account. Try again or choose a different method.',
|
44 | 44 | EmailCreateAccount: 'Could not create Email account. Try again or choose a different method.',
|
45 |
| - Callback: 'Try again or choose a different method.', |
| 45 | + Callback: 'Could not authenticate. Try again or choose a different method.', |
46 | 46 | OAuthAccountNotLinked: 'This auth method is linked to another account. To link to this account first unlink the other account.',
|
47 | 47 | EmailSignin: 'Failed to send email. Make sure you entered your email address correctly.',
|
48 |
| - CredentialsSignin: 'Auth failed. Try again or choose a different method.', |
| 48 | + CredentialsSignin: 'Could not authenticate. Try again or choose a different method.', |
49 | 49 | default: 'Auth failed. Try again or choose a different method.'
|
50 | 50 | }
|
51 | 51 |
|
52 | 52 | export function authErrorMessage (error) {
|
53 | 53 | return error && (authErrorMessages[error] ?? authErrorMessages.default)
|
54 | 54 | }
|
55 | 55 |
|
56 |
| -export default function Login ({ providers, callbackUrl, multiAuth, error, text, Header, Footer }) { |
| 56 | +export default function Login ({ providers, callbackUrl, multiAuth, error, text, Header, Footer, signin }) { |
57 | 57 | const [errorMessage, setErrorMessage] = useState(authErrorMessage(error))
|
58 | 58 | const router = useRouter()
|
59 | 59 |
|
| 60 | + // signup/signin awareness cookie |
| 61 | + useEffect(() => { |
| 62 | + const cookieOptions = [ |
| 63 | + `signin=${!!signin}`, |
| 64 | + 'path=/', |
| 65 | + 'max-age=' + (signin ? 60 * 60 * 24 : 0), // 24 hours if signin is true, expire the cookie otherwise |
| 66 | + 'SameSite=Lax', |
| 67 | + process.env.NODE_ENV === 'production' ? 'Secure' : '' |
| 68 | + ].filter(Boolean).join(';') |
| 69 | + |
| 70 | + document.cookie = cookieOptions |
| 71 | + }, [signin]) |
| 72 | + |
60 | 73 | if (router.query.type === 'lightning') {
|
61 | 74 | return <LightningAuthWithExplainer callbackUrl={callbackUrl} text={text} multiAuth={multiAuth} />
|
62 | 75 | }
|
|
0 commit comments