mirror of
https://github.com/QingWei-Li/notea.git
synced 2024-12-05 08:24:46 +03:00
feat: check auth
This commit is contained in:
parent
834546c787
commit
598e1dd227
@ -2,8 +2,11 @@ import { Editor } from './editor'
|
||||
import { List } from './list'
|
||||
import { PageListState } from '../containers/page-list'
|
||||
import { PageState } from '../containers/page'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
export const Layout = () => {
|
||||
const router = useRouter()
|
||||
|
||||
return (
|
||||
<section className="flex h-screen">
|
||||
<aside className="w-10 bg-gray-200">toolbar</aside>
|
||||
@ -15,7 +18,7 @@ export const Layout = () => {
|
||||
<main className="flex-auto overflow-y-auto">
|
||||
<nav className="fixed bg-white w-full z-10 p-2 text-sm">导航</nav>
|
||||
<article className="m-auto pt-40 pb-40 prose prose-sm h-full">
|
||||
<PageState.Provider>
|
||||
<PageState.Provider initialState={router.query.id as string}>
|
||||
<Editor />
|
||||
</PageState.Provider>
|
||||
</article>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { createContainer } from 'unstated-next'
|
||||
import useFetch from 'use-http'
|
||||
|
||||
@ -10,13 +10,13 @@ export interface PageModel {
|
||||
content?: string
|
||||
}
|
||||
|
||||
const usePage = () => {
|
||||
const usePage = (id?: string) => {
|
||||
const [page, setPage] = useState<PageModel>()
|
||||
const { get, post } = useFetch(`/api/pages`)
|
||||
const { get, post, response } = useFetch(`/api/pages`)
|
||||
|
||||
const getById = async (id: string) => {
|
||||
console.log(111, id)
|
||||
const data = await get(id)
|
||||
console.log(111, response.headers)
|
||||
|
||||
setPage({
|
||||
id: '0',
|
||||
@ -27,6 +27,12 @@ const usePage = () => {
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
getById(id)
|
||||
}
|
||||
}, [id])
|
||||
|
||||
const savePage = async (data: PageModel) => {
|
||||
await post({
|
||||
id: data.id,
|
||||
|
@ -1,5 +1,24 @@
|
||||
import { GetServerSideProps } from 'next'
|
||||
import { getSession } from 'next-auth/client'
|
||||
import { Layout } from '../components/layout'
|
||||
|
||||
const IndexPage = () => <Layout></Layout>
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const session = await getSession(ctx)
|
||||
|
||||
if (!session) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/api/auth/signin',
|
||||
permanent: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
props: {},
|
||||
}
|
||||
}
|
||||
|
||||
export default IndexPage
|
||||
|
@ -1,7 +1,5 @@
|
||||
import { Layout } from '../../components/layout'
|
||||
import IndexPage, { getServerSideProps } from '..'
|
||||
|
||||
const PagePage = () => {
|
||||
return <Layout></Layout>
|
||||
}
|
||||
export { getServerSideProps }
|
||||
|
||||
export default PagePage
|
||||
export default IndexPage
|
||||
|
Loading…
Reference in New Issue
Block a user