-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from h8570rg/develop
Prd
- Loading branch information
Showing
171 changed files
with
11,209 additions
and
9,644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
NEXT_PUBLIC_SERVICE_NAME=janreco | ||
NEXT_PUBLIC_SUPABASE_URL= | ||
NEXT_PUBLIC_SUPABASE_ANON_KEY= | ||
GOOGLE_CLIENT_ID= | ||
GOOGLE_SECRET= | ||
OPENAI_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
node_modules | ||
.next | ||
.npmrc | ||
.env.local | ||
.vscode | ||
.env* | ||
tsconfig.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"cSpell.words": [ | ||
"fkey", | ||
"janreco", | ||
"nextjs", | ||
"nextui", | ||
"Noto", | ||
"OPENAI", | ||
"Postgrest", | ||
"svgr", | ||
"toastify" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Link from "next/link"; | ||
import { Button } from "@/components/Button"; | ||
|
||
/** | ||
* @see https://supabase.com/docs/guides/auth/server-side/oauth-with-pkce-flow-for-ssr | ||
*/ | ||
export default function AuthCodeErrorPage() { | ||
return ( | ||
<div className="flex flex-col items-center"> | ||
<h1>ログインに失敗しました</h1> | ||
<Button as={Link} href="/login" className="mt-4" color="primary"> | ||
ログイン画面へ戻る | ||
</Button> | ||
</div> | ||
); | ||
} |
84 changes: 84 additions & 0 deletions
84
app/(auth)/(routes)/login/(components)/LoginForm/actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
"use server"; | ||
|
||
import { revalidatePath } from "next/cache"; | ||
import { redirect } from "next/navigation"; | ||
import { z } from "zod"; | ||
import { schema } from "@/lib/utils/schema"; | ||
import { createClient } from "@/lib/utils/supabase/server"; | ||
import { getURL } from "@/lib/utils/url"; | ||
|
||
type State = { | ||
errors?: { | ||
base?: string[]; | ||
email?: string[]; | ||
password?: string[]; | ||
}; | ||
}; | ||
|
||
const signInEmailSchema = z.object({ | ||
email: schema.email, | ||
password: schema.password, | ||
}); | ||
|
||
/** | ||
* @see https://supabase.com/docs/guides/auth/server-side/nextjs | ||
*/ | ||
export async function signInEmail( | ||
prevState: State, | ||
formData: FormData, | ||
): Promise<State> { | ||
const validatedFields = signInEmailSchema.safeParse({ | ||
email: formData.get("email"), | ||
password: formData.get("password"), | ||
}); | ||
|
||
if (!validatedFields.success) { | ||
return { | ||
errors: validatedFields.error.flatten().fieldErrors, | ||
}; | ||
} | ||
|
||
const { email, password } = validatedFields.data; | ||
|
||
const supabase = createClient(); | ||
|
||
const { error } = await supabase.auth.signInWithPassword({ | ||
email, | ||
password, | ||
}); | ||
|
||
if (error) { | ||
return { | ||
errors: { | ||
base: ["メールアドレスまたはパスワードが間違っています。"], | ||
}, | ||
}; | ||
} | ||
|
||
revalidatePath("/", "layout"); | ||
redirect("/"); | ||
} | ||
|
||
/** | ||
* @see https://supabase.com/docs/guides/auth/server-side/oauth-with-pkce-flow-for-ssr?queryGroups=environment&environment=server | ||
*/ | ||
export async function signInWithGoogle() { | ||
const supabase = createClient(); | ||
const { data } = await supabase.auth.signInWithOAuth({ | ||
provider: "google", | ||
options: { | ||
redirectTo: `${getURL()}api/auth/callback`, | ||
}, | ||
}); | ||
|
||
if (data.url) { | ||
redirect(data.url); // use the redirect API for your server framework | ||
} | ||
} | ||
|
||
export async function signInAnonymously() { | ||
const supabase = createClient(); | ||
await supabase.auth.signInAnonymously(); | ||
|
||
redirect("/"); | ||
} |
44 changes: 44 additions & 0 deletions
44
app/(auth)/(routes)/login/(components)/LoginForm/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"use client"; | ||
|
||
import { useFormState } from "react-dom"; | ||
import { Button } from "@/components/Button"; | ||
import { Input } from "@/components/Input"; | ||
import { signInEmail } from "./actions"; | ||
|
||
/** | ||
* @see https://supabase.com/docs/guides/auth/server-side/nextjs | ||
*/ | ||
export function LoginForm({ className }: { className?: string }) { | ||
const [state, formAction] = useFormState(signInEmail, {}); | ||
|
||
return ( | ||
<form className={className} action={formAction} noValidate> | ||
<div className="space-y-2.5"> | ||
<Input | ||
id="email" | ||
type="email" | ||
name="email" | ||
autoComplete="username" | ||
required | ||
label="メールアドレス" | ||
errorMessage={state.errors?.email?.[0]} | ||
/> | ||
<Input | ||
id="current-password" | ||
name="password" | ||
label="パスワード" | ||
type="password" | ||
autoComplete="current-password" | ||
required | ||
errorMessage={state.errors?.password?.[0]} | ||
/> | ||
</div> | ||
{state.errors?.base && ( | ||
<p className="mt-1 p-1 text-tiny text-danger">{state.errors.base}</p> | ||
)} | ||
<Button className="mt-2.5" fullWidth color="primary" type="submit"> | ||
ログイン | ||
</Button> | ||
</form> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
app/(auth)/(routes)/login/(components)/SocialProviders/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use client"; | ||
|
||
import classNames from "classnames"; | ||
import { Button } from "@/components/Button"; | ||
import { GoogleIcon } from "@/components/SocialProviderIcon"; | ||
import { signInWithGoogle } from "../LoginForm/actions"; | ||
|
||
export function SocialProviders({ className }: { className?: string }) { | ||
return ( | ||
<ul className={classNames("space-y-2", className)}> | ||
<li className="w-full"> | ||
<Button | ||
fullWidth | ||
className="flex items-center justify-center gap-3" | ||
variant="bordered" | ||
onClick={() => signInWithGoogle()} | ||
> | ||
<GoogleIcon className="w-5" /> | ||
<span>Google でログイン</span> | ||
</Button> | ||
</li> | ||
<li className="w-full"> | ||
<Button | ||
fullWidth | ||
variant="bordered" | ||
onClick={() => alert("Coming soon!")} // TODO: 実装 | ||
> | ||
<span>ログインせずに始める</span> | ||
</Button> | ||
</li> | ||
</ul> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Metadata } from "next"; | ||
import Link from "next/link"; | ||
import { Divider } from "@/components/Divider"; | ||
import { LoginForm } from "./(components)/LoginForm"; | ||
import { SocialProviders } from "./(components)/SocialProviders"; | ||
|
||
export const metadata: Metadata = { | ||
title: "ログイン", | ||
}; | ||
|
||
export default function LoginPage() { | ||
return ( | ||
<> | ||
<h1 className="mx-auto mb-4 w-fit text-large font-bold">ログイン</h1> | ||
<SocialProviders /> | ||
<div className="my-4 flex items-center gap-4"> | ||
<Divider className="shrink" /> | ||
<span>or</span> | ||
<Divider className="shrink" /> | ||
</div> | ||
<LoginForm /> | ||
<p className="mt-4 text-center text-small"> | ||
アカウントをお持ちでない方は | ||
<Link className="link" href="/sign-up"> | ||
新規登録 | ||
</Link> | ||
</p> | ||
</> | ||
); | ||
} |
Oops, something went wrong.