stacker.news/pages/signup.js

68 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-01-10 00:56:19 +00:00
import { providers, getSession } from 'next-auth/client'
import Link from 'next/link'
2023-05-01 20:58:30 +00:00
import LayoutStatic from '../components/layout-static'
2023-01-10 00:56:19 +00:00
import Login from '../components/login'
2023-05-07 13:33:51 +00:00
import { isExternal } from '../lib/url'
2023-01-10 00:56:19 +00:00
export async function getServerSideProps ({ req, res, query: { callbackUrl, error = null } }) {
const session = await getSession({ req })
// assume external by default so we will use fallback callback
let external = true
try {
external = isExternal(decodeURIComponent(callbackUrl))
} catch (err) {
console.error('error decoding callback:', callbackUrl, err)
}
2023-05-07 11:59:19 +00:00
if (external) {
// This is a hotfix for open redirects. See https://github.com/stackernews/stacker.news/issues/264
2023-05-07 13:33:51 +00:00
callbackUrl = '/'
2023-05-07 11:59:19 +00:00
}
2023-01-10 00:56:19 +00:00
if (session && res && callbackUrl) {
res.writeHead(302, {
Location: callbackUrl
})
res.end()
return { props: {} }
}
return {
props: {
providers: await providers({ req, res }),
callbackUrl,
error
}
}
}
function SignUpHeader () {
return (
<>
<h3 className='w-100 pb-2'>
Sign up
</h3>
2023-02-04 23:31:18 +00:00
<div className='font-weight-bold text-muted pb-4'>Join 10,000+ bitcoiners and start stacking sats today</div>
2023-01-10 00:56:19 +00:00
</>
)
}
function SignUpFooter ({ callbackUrl }) {
return (
<small className='font-weight-bold text-muted pt-4'>Already have an account? <Link href={{ pathname: '/login', query: { callbackUrl } }}>login</Link></small>
)
}
export default function SignUp ({ ...props }) {
return (
2023-05-01 20:58:30 +00:00
<LayoutStatic>
<Login
Header={() => <SignUpHeader />}
Footer={() => <SignUpFooter callbackUrl={props.callbackUrl} />}
text='Sign up'
{...props}
/>
2023-05-01 20:58:30 +00:00
</LayoutStatic>
2023-01-10 00:56:19 +00:00
)
}