diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 0da6123..5f1b140 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -17,10 +17,12 @@ export default (req: NextApiRequest, res: NextApiResponse) => { async authorize(credentials) { const { password } = credentials - if (password !== getEnv('PASSWORD')) { + if (password !== getEnv('PASSWORD').toString()) { return null } + console.log('ok') + return { logged: true, } diff --git a/pages/index.tsx b/pages/index.tsx index 53a19ac..833504f 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -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 = () => +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 } export default IndexPage diff --git a/pages/page/[id].tsx b/pages/page/[id].tsx index 2663285..d3c769c 100644 --- a/pages/page/[id].tsx +++ b/pages/page/[id].tsx @@ -1,5 +1,3 @@ -import IndexPage, { getServerSideProps } from '..' - -export { getServerSideProps } +import IndexPage from '..' export default IndexPage