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) { async authorize(credentials) {
const { password } = credentials const { password } = credentials
if (password !== getEnv('PASSWORD')) { if (password !== getEnv<string>('PASSWORD').toString()) {
return null return null
} }
console.log('ok')
return { return {
logged: true, logged: true,
} }

View File

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

View File

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