Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Created authenticated wrapper #247

Merged
merged 5 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions client/app/post/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import CreatePostTemplate from "@/modules/post/create/template"

import { siteConfig } from "@/config/site"
import CommonPageLayout from "@/components/layouts/common"
import AuthenticatedPageWrapper from "@/components/wrappers/authenticated"

export const metadata = siteConfig.page.createPost.metadata

const CreatePostPage = () => {
return (
<CommonPageLayout title={siteConfig.page.createPost.name}>
<CreatePostTemplate />
</CommonPageLayout>
<AuthenticatedPageWrapper>
<CommonPageLayout title={siteConfig.page.createPost.name}>
<CreatePostTemplate />
</CommonPageLayout>
</AuthenticatedPageWrapper>
)
}

Expand Down
31 changes: 31 additions & 0 deletions client/components/wrappers/authenticated.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use client"

import React, { PropsWithChildren } from "react"

import { siteConfig } from "@/config/site"
import useUserStore from "@/hooks/state/user/store"
import HighlightedLink from "@/components/customized-ui/links/highlighted"

interface IAuthenticatedWrapperProps {}

const AuthenticatedPageWrapper: React.FunctionComponent<
PropsWithChildren<IAuthenticatedWrapperProps>
> = ({ children }) => {
const isUserSignIn = useUserStore((state) => state.isSignIn)

if (!isUserSignIn)
return (
<div className="flex h-screen flex-col items-center justify-center gap-4 rounded-lg p-4">
<span className="text-5xl">🥲</span>
<h6>
請先
<HighlightedLink href={siteConfig.page.auth.href}>
登入
</HighlightedLink>
</h6>
</div>
)
return <>{children}</>
}

export default AuthenticatedPageWrapper