fix: remove getServerSideProps

This commit is contained in:
liqingwei 2021-02-16 13:31:42 +08:00
parent 1a20c4b290
commit 467f7a8950
3 changed files with 14 additions and 19 deletions

View File

@ -17,10 +17,12 @@ export default (req: NextApiRequest, res: NextApiResponse) => {
async authorize(credentials) {
const { password } = credentials
if (password !== getEnv('PASSWORD')) {
if (password !== getEnv<string>('PASSWORD').toString()) {
return null
}
console.log('ok')
return {
logged: true,
}

View File

@ -1,24 +1,19 @@
import { GetServerSideProps } from 'next'
import { getSession } from 'next-auth/client'
import { useSession } from 'next-auth/client'
import { Layout } from 'components/layout'
import { useRouter } from 'next/router'
const IndexPage = () => <Layout></Layout>
const IndexPage = () => {
const [session, loading] = useSession()
const router = useRouter()
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const session = await getSession(ctx)
if (loading) return null
if (!session) {
return {
redirect: {
destination: '/api/auth/signin',
permanent: false,
},
}
if (!loading && !session) {
router.push('/api/auth/signin')
return null
}
return {
props: {},
}
return <Layout></Layout>
}
export default IndexPage

View File

@ -1,5 +1,3 @@
import IndexPage, { getServerSideProps } from '..'
export { getServerSideProps }
import IndexPage from '..'
export default IndexPage