-
Notifications
You must be signed in to change notification settings - Fork 1
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 #137 from YukiOnishi1129/feature/web-front-supabas…
…e-auth feat(web-v2): web-front-supabase-auth-v2
- Loading branch information
Showing
38 changed files
with
829 additions
and
8 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,2 +1,5 @@ | ||
BFF_API_URL= | ||
NEXT_PUBLIC_BFF_API_URL= | ||
NEXT_PUBLIC_BFF_API_URL= | ||
|
||
NEXT_PUBLIC_SUPABASE_URL= | ||
NEXT_PUBLIC_SUPABASE_ANON_KEY= |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,20 @@ | ||
import { redirect } from "next/navigation"; | ||
import { Suspense } from "react"; | ||
|
||
import { getUser } from "@/features/auth/actions/user"; | ||
import { LoginTemplate } from "@/features/auth/components/Template"; | ||
|
||
import { ScreenLoader } from "@/components/layout/ScreenLoader"; | ||
|
||
export default async function Login() { | ||
const user = await getUser(); | ||
if (user) { | ||
redirect("/dashboard"); | ||
} | ||
|
||
return ( | ||
<Suspense fallback={<ScreenLoader />}> | ||
<LoginTemplate /> | ||
</Suspense> | ||
); | ||
} |
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,39 @@ | ||
import { type CookieOptions, createServerClient } from "@supabase/ssr"; | ||
import { cookies } from "next/headers"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams } = new URL(request.url); | ||
const code = searchParams.get("code"); | ||
// if "next" is in param, use it as the redirect URL | ||
const next = searchParams.get("next") ?? "/"; | ||
if (code) { | ||
const cookieStore = cookies(); | ||
const supabase = createServerClient( | ||
process.env.NEXT_PUBLIC_SUPABASE_URL!, | ||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, | ||
{ | ||
cookies: { | ||
get(name: string) { | ||
return cookieStore.get(name)?.value; | ||
}, | ||
set(name: string, value: string, options: CookieOptions) { | ||
cookieStore.set({ name, value, ...options }); | ||
}, | ||
remove(name: string, options: CookieOptions) { | ||
cookieStore.delete({ name, ...options }); | ||
}, | ||
}, | ||
} | ||
); | ||
const { error } = await supabase.auth.exchangeCodeForSession(code); | ||
if (!error) { | ||
return NextResponse.redirect(`${process.env.WEB_DOMAIN}${next}`); | ||
} | ||
} | ||
|
||
// return the user to an error page with instructions | ||
return NextResponse.redirect( | ||
`${process.env.WEB_DOMAIN}/auth/auth-code-error` | ||
); | ||
} |
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,3 @@ | ||
export default function Home() { | ||
return <div>Dashboard</div>; | ||
} |
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,5 +1,5 @@ | ||
import { ArticleDashboardTemplate } from "@/features/articles/components/Template"; | ||
import { HomeTemplate } from "@/features/home/components/Template/HomeTemplate"; | ||
|
||
export default function Home() { | ||
return <ArticleDashboardTemplate />; | ||
return <HomeTemplate />; | ||
} |
19 changes: 19 additions & 0 deletions
19
web/client-v2/src/components/layout/BaseLayout/BaseLayout.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,19 @@ | ||
import { ReactNode } from "react"; | ||
|
||
import { getUser } from "@/features/auth/actions/user"; | ||
|
||
import { LoggedBaseLayout } from "./LoggedBaseLayout"; | ||
import { NotLoggedBaseLayout } from "./NotLoggedBaseLayout"; | ||
|
||
export const BaseLayout = async ({ children }: { children: ReactNode }) => { | ||
const user = await getUser(); | ||
return ( | ||
<> | ||
{user ? ( | ||
<LoggedBaseLayout user={user}>{children}</LoggedBaseLayout> | ||
) : ( | ||
<NotLoggedBaseLayout>{children}</NotLoggedBaseLayout> | ||
)} | ||
</> | ||
); | ||
}; |
50 changes: 50 additions & 0 deletions
50
web/client-v2/src/components/layout/BaseLayout/LoggedBaseLayout.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,50 @@ | ||
import { User } from "@supabase/supabase-js"; | ||
import { FC, ReactNode } from "react"; | ||
|
||
// import { fetchFavoriteArticleFoldersAPI } from "@/features/favoriteArticleFolders/actions/favoriteArticleFolders"; | ||
// import { fetchMyFeedFoldersAPI } from "@/features/myFeedFolders/actions/myFeedFolder"; | ||
|
||
import { Header } from "@/components/layout/Header"; | ||
|
||
// import { LoggedBottomNavigationMenu } from "../BottomNavigationMenu"; | ||
// import { DesktopSidebar } from "../Sidebar"; | ||
|
||
type LoggedBaseLayoutProps = { | ||
user: User; | ||
children: ReactNode; | ||
}; | ||
|
||
export const LoggedBaseLayout: FC<LoggedBaseLayoutProps> = async ({ | ||
user, | ||
children, | ||
}) => { | ||
// const myFeedFolderRes = await fetchMyFeedFoldersAPI({}); | ||
// const favoriteArticleFolderRes = await fetchFavoriteArticleFoldersAPI({}); | ||
return ( | ||
<div> | ||
<header className="overflow-hidden"> | ||
<Header user={user} /> | ||
</header> | ||
|
||
<div className="h-12 md:h-16" /> | ||
<main className="md:flex"> | ||
<div className="invisible fixed h-lvh w-[200px] md:visible"> | ||
{/* <DesktopSidebar | ||
user={user} | ||
myFeedFolders={myFeedFolderRes.data.myFeedFolders} | ||
favoriteArticleFolders={ | ||
favoriteArticleFolderRes.data.favoriteArticleFolders | ||
} | ||
/> */} | ||
</div> | ||
<div className="invisible mr-[10px] w-[200px] md:visible" /> | ||
|
||
<div className="mx-auto w-[90%] md:w-[70%]">{children}</div> | ||
</main> | ||
|
||
{/* <footer className="fixed inset-x-0 bottom-0 z-50 block border-t border-gray-200 md:hidden"> | ||
<LoggedBottomNavigationMenu /> | ||
</footer> */} | ||
</div> | ||
); | ||
}; |
28 changes: 28 additions & 0 deletions
28
web/client-v2/src/components/layout/BaseLayout/NotLoggedBaseLayout.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,28 @@ | ||
import { FC, ReactNode } from "react"; | ||
|
||
import { Header } from "../Header"; | ||
|
||
type NotLoggedBaseLayoutProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
export const NotLoggedBaseLayout: FC<NotLoggedBaseLayoutProps> = async ({ | ||
children, | ||
}) => { | ||
return ( | ||
<div> | ||
<header className="overflow-hidden"> | ||
<Header /> | ||
</header> | ||
|
||
<div className="h-12 md:h-16" /> | ||
<main className="md:flex"> | ||
<div className="mx-auto w-[90%] md:w-[70%]">{children}</div> | ||
</main> | ||
|
||
{/* <footer className="fixed inset-x-0 bottom-0 z-50 block border-t border-gray-200 md:hidden"> | ||
<NotLoggedBottomNavigationMenu /> | ||
</footer> */} | ||
</div> | ||
); | ||
}; |
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 @@ | ||
export * from "./BaseLayout"; |
26 changes: 26 additions & 0 deletions
26
web/client-v2/src/components/layout/Header/DesktopHeader/DesktopHeader.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,26 @@ | ||
"use client"; | ||
import { User } from "@supabase/supabase-js"; | ||
import Link from "next/link"; | ||
import { FC } from "react"; | ||
|
||
import { LoggedMenu } from "./LoggedMenu"; | ||
import { NotLoggedMenu } from "./NotLoggedMenu"; | ||
|
||
type DesktopHeaderProps = { | ||
user?: User; | ||
}; | ||
|
||
export const DesktopHeader: FC<DesktopHeaderProps> = async ({ | ||
user, | ||
}: DesktopHeaderProps) => { | ||
return ( | ||
<div className="fixed z-50 flex h-16 w-screen items-center justify-between border-b border-gray-300 bg-card px-8 shadow-md"> | ||
<Link href={user ? "/dashboard" : "/"} className="cursor-pointer"> | ||
<h1 className="text-2xl font-bold">Check Picks</h1> | ||
</Link> | ||
<div className="flex items-center justify-end"> | ||
{user ? <LoggedMenu user={user} /> : <NotLoggedMenu />} | ||
</div> | ||
</div> | ||
); | ||
}; |
12 changes: 12 additions & 0 deletions
12
web/client-v2/src/components/layout/Header/DesktopHeader/LoggedMenu.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,12 @@ | ||
"use client"; | ||
import { User } from "@supabase/supabase-js"; | ||
import { FC } from "react"; | ||
|
||
import { AvatarDropdownMenu } from "../DropdownMenu"; | ||
|
||
type LoggedMenuProps = { | ||
user?: User; | ||
}; | ||
export const LoggedMenu: FC<LoggedMenuProps> = ({ user }: LoggedMenuProps) => { | ||
return <AvatarDropdownMenu user={user} />; | ||
}; |
16 changes: 16 additions & 0 deletions
16
web/client-v2/src/components/layout/Header/DesktopHeader/NotLoggedMenu.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,16 @@ | ||
"use client"; | ||
|
||
import Link from "next/link"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
|
||
export const NotLoggedMenu = () => { | ||
return ( | ||
<div className="grid grid-cols-2"> | ||
<Link href="/login"> | ||
<Button variant={"ghost"}>Login</Button> | ||
</Link> | ||
<Button variant={"destructive"}>Signup</Button> | ||
</div> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
web/client-v2/src/components/layout/Header/DesktopHeader/index.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 @@ | ||
export * from "./DesktopHeader"; |
55 changes: 55 additions & 0 deletions
55
web/client-v2/src/components/layout/Header/DropdownMenu/AvatarDropdownMenu.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,55 @@ | ||
"use client"; | ||
import { User } from "@supabase/supabase-js"; | ||
import { FC } from "react"; | ||
import { FiLogOut } from "react-icons/fi"; | ||
import { GrUser } from "react-icons/gr"; | ||
|
||
import { logout } from "@/features/auth/actions/auth"; | ||
|
||
import { UserAvatar } from "@/components/ui/avatar"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuTrigger, | ||
DropdownMenuContent, | ||
DropdownMenuSeparator, | ||
DropdownMenuItem, | ||
} from "@/components/ui/dropdown-menu"; | ||
|
||
type AvatarDropdownMenuProps = { | ||
user?: User; | ||
}; | ||
|
||
export const AvatarDropdownMenu: FC<AvatarDropdownMenuProps> = ({ | ||
user, | ||
}: AvatarDropdownMenuProps) => { | ||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<div className="md:flex md:justify-end"> | ||
<UserAvatar user={user} /> | ||
</div> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align="end" className="w-[100px]"> | ||
<DropdownMenuItem className="cursor-pointer"> | ||
<GrUser /> | ||
<span className="pl-2">Profile</span> | ||
</DropdownMenuItem> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuItem | ||
className="cursor-pointer" | ||
role="button" | ||
tabIndex={1} | ||
onClick={() => logout()} | ||
onKeyDown={(e) => { | ||
if (e.key === "Enter" || e.key === " ") { | ||
logout(); | ||
} | ||
}} | ||
> | ||
<FiLogOut /> | ||
<span className="pl-2">Logout</span> | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
web/client-v2/src/components/layout/Header/DropdownMenu/index.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 @@ | ||
export * from "./AvatarDropdownMenu"; |
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,29 @@ | ||
import { User } from "@supabase/supabase-js"; | ||
import { FC } from "react"; | ||
|
||
import { DesktopHeader } from "./DesktopHeader"; | ||
|
||
type HeaderProps = { | ||
user?: User; | ||
}; | ||
|
||
export const Header: FC<HeaderProps> = async ({ user }) => { | ||
// const myFeedFolderRes = await fetchMyFeedFoldersAPI({}); | ||
// const favoriteArticleFolderRes = await fetchFavoriteArticleFoldersAPI({}); | ||
return ( | ||
<> | ||
<div className="hidden md:block"> | ||
<DesktopHeader user={user} /> | ||
</div> | ||
<div className="block md:hidden"> | ||
{/* <MobileHeader | ||
user={user} | ||
myFeedFolders={myFeedFolderRes.data.myFeedFolders} | ||
favoriteArticleFolders={ | ||
favoriteArticleFolderRes.data.favoriteArticleFolders | ||
} | ||
/> */} | ||
</div> | ||
</> | ||
); | ||
}; |
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 @@ | ||
export * from "./Header"; |
9 changes: 9 additions & 0 deletions
9
web/client-v2/src/components/layout/ScreenLoader/ScreenLoader.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,9 @@ | ||
import { Loader } from "@/components/ui/loader"; | ||
|
||
export const ScreenLoader = () => { | ||
return ( | ||
<div className="flex h-screen w-full items-center justify-center"> | ||
<Loader /> | ||
</div> | ||
); | ||
}; |
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 @@ | ||
export * from "./ScreenLoader"; |
Oops, something went wrong.