From 07cc3eb74bafc4ac658336d99cc149118c1514ed Mon Sep 17 00:00:00 2001 From: Fun117 Date: Mon, 4 Nov 2024 14:24:40 +0900 Subject: [PATCH] Update MD --- README.md | 9 ++++++- packages/nextjs/README.md | 53 ++++++++++++++++++++++++++++++++++++++- packages/react/README.md | 1 + 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 packages/react/README.md diff --git a/README.md b/README.md index f20ed9e..90acfcc 100644 --- a/README.md +++ b/README.md @@ -35,4 +35,11 @@ Scratch Auth is licensed under the MIT License. For more details, please refer t If you have any questions or feedback, feel free to reach out via [GitHub Discussions](https://github.com/scratch-auth/pkg/discussions). -Thank you for using Scratch Auth! \ No newline at end of file +Thank you for using Scratch Auth! + +--- + +# Document + +- [Next.js](https://github.com/scratch-auth/pkg/blob/main/packages/nextjs/README.md) +- [React](https://github.com/scratch-auth/pkg/blob/main/packages/react/README.md) \ No newline at end of file diff --git a/packages/nextjs/README.md b/packages/nextjs/README.md index 818d4d2..12d6257 100644 --- a/packages/nextjs/README.md +++ b/packages/nextjs/README.md @@ -28,6 +28,7 @@ SCRATCH_AUTH_SECRET_KEY=*************************************** This page will decode the session and verify account information. You need to add this file to the path of the `redirect_url` that you set in `scratch-auth.config.ts`. During the redirect, the session will be set in the `privateCode` parameter. ```tsx filename="app/api/auth/page.tsx" +// /src/app/api/auth/page.tsx "use client"; import React, { useEffect } from "react"; @@ -72,6 +73,7 @@ By using Scratch Auth’s pre-built components, you can control the content disp - ``: An unstyled component that links to the login page. In this example, since no properties or environment variables are specified for the login URL, the component will link to the login page of the account portal. ```tsx filename="app/page.tsx" +// /src/app/page.tsx import React from "react"; import { LogInButton, @@ -106,6 +108,7 @@ export default function Page() { | debug | Debug mode | ```tsx filename="scratch-auth.config.ts" +// /scratch-auth.config.ts import { ScratchAuthConfig } from "@scratch-auth/nextjs/src/types"; import { type ClassValue, clsx } from "clsx"; import { twMerge } from "tailwind-merge"; @@ -137,4 +140,52 @@ up and create the first user. -[@Looky1173](https://github.com/Looky1173) / [@Fun117](https://github.com/Fun117) \ No newline at end of file +[@Looky1173](https://github.com/Looky1173) / [@Fun117](https://github.com/Fun117) + +--- + +# プロバイダー + +バージョン `0.0.2` で実装される認証プロバイダー機能です。 + +プロバイダーの設定をすることで、ログインしていないユーザーに特定の制限を設定できます。 + +```ts +type ConfigProps = { + noLogin: { + redirect?: string; + function?: () => void; + children?: React.ReactNode; + }; +}; +``` + +制限したい要素の親要素に、`ScratchAuthProvider` を設置してください。 + +```tsx +// /src/app/dashboard/layout.tsx +import ScratchAuthProvider from "@scratch-auth/nextjs/src/components/provider"; + +export default function DashboardLayout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return {children}; +} +``` + +ログインしているユーザーは認証プロバイダーで制限されている要素を表示することができます。 + +```tsx +// /src/app/dashboard/page.tsx +import React from 'react' + +function page() { + return ( +
page
+ ) +} + +export default page +``` \ No newline at end of file diff --git a/packages/react/README.md b/packages/react/README.md new file mode 100644 index 0000000..463e41b --- /dev/null +++ b/packages/react/README.md @@ -0,0 +1 @@ +# COMING SOON \ No newline at end of file