This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
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.
- Loading branch information
Showing
17 changed files
with
409 additions
and
94 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
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,27 @@ | ||
import type { Metadata } from "next"; | ||
import { redirect } from "next/navigation"; | ||
import { createSupabaseServerClient } from "utils/supabase/server"; | ||
import { DeleteUserCard } from "./delete-user-card"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Account", | ||
description: "Change your account settings the iWallpaper platform", | ||
}; | ||
|
||
export default async function SettingsAccountPage() { | ||
const supabase = createSupabaseServerClient(); | ||
|
||
const { | ||
data: { user }, | ||
} = await supabase.auth.getUser(); | ||
|
||
if (!user) { | ||
redirect("/sign-in"); | ||
} | ||
|
||
return ( | ||
<div className="space-y-4"> | ||
<DeleteUserCard /> | ||
</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,15 @@ | ||
import { PageTitle } from "components/ui/page-title"; | ||
import type { PropsWithChildren } from "react"; | ||
import { NavigationBar } from "./navigation-bar"; | ||
|
||
export default function SettingsLayout({ children }: PropsWithChildren) { | ||
return ( | ||
<> | ||
<PageTitle>Settings</PageTitle> | ||
<div className="flex flex-col md:flex-row gap-x-16 gap-y-8"> | ||
<NavigationBar /> | ||
<div className="grow">{children}</div> | ||
</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,36 @@ | ||
"use client"; | ||
|
||
import { cn } from "components/ui/utils"; | ||
import Link from "next/link"; | ||
import { usePathname } from "next/navigation"; | ||
|
||
const links = [ | ||
{ text: "Profile", href: "/settings/profile" }, | ||
{ text: "Account", href: "/settings/account" }, | ||
{ text: "Third Party Services", href: "/settings/third-party-services" }, | ||
] as const; | ||
|
||
export function NavigationBar() { | ||
const pathname = usePathname(); | ||
|
||
return ( | ||
<aside className="shrink-0"> | ||
<nav className="flex flex-col gap-3 lg:min-w-64"> | ||
{links.map(({ href, text }) => ( | ||
<Link | ||
key={href} | ||
href={href} | ||
className={cn( | ||
"p-1 text-sm", | ||
href === pathname | ||
? "font-semibold" | ||
: "text-muted-foreground hover:text-foreground transition-colors", | ||
)} | ||
> | ||
{text} | ||
</Link> | ||
))} | ||
</nav> | ||
</aside> | ||
); | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use server"; | ||
|
||
import { createSupabaseServerClient } from "utils/supabase/server"; | ||
|
||
type UpdateNicknameState = { | ||
nickname: string; | ||
error: string; | ||
}; | ||
|
||
export async function updateNickname( | ||
state: UpdateNicknameState, | ||
formData: FormData, | ||
) { | ||
const supabase = createSupabaseServerClient(); | ||
|
||
const nickname = formData.get("nickname")!.toString(); | ||
|
||
const { error } = await supabase.auth.updateUser({ data: { nickname } }); | ||
|
||
if (error) { | ||
return { ...state, error: error.message }; | ||
} | ||
|
||
return { nickname, 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
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,36 @@ | ||
import type { Metadata } from "next"; | ||
import { redirect } from "next/navigation"; | ||
import { createSupabaseServerClient } from "utils/supabase/server"; | ||
import { AvatarCard } from "./avatar-card"; | ||
import { NicknameCard } from "./nickname-card"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Profile", | ||
description: "Change your profile on the iWallpaper platform", | ||
}; | ||
|
||
export default async function SettingsProfilePage() { | ||
const supabase = createSupabaseServerClient(); | ||
|
||
const { | ||
data: { user }, | ||
} = await supabase.auth.getUser(); | ||
|
||
if (!user) { | ||
redirect("/sign-in"); | ||
} | ||
|
||
return ( | ||
<div className="space-y-4"> | ||
<AvatarCard initialAvatarUrl={user.user_metadata.avatar_url} /> | ||
<NicknameCard | ||
initialNickname={ | ||
user.user_metadata.nickname ?? | ||
user.user_metadata.full_name ?? | ||
user.user_metadata.user_name ?? | ||
"" | ||
} | ||
/> | ||
</div> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
app/(with-framework)/settings/third-party-services/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,46 @@ | ||
"use server"; | ||
|
||
import type { Provider, UserIdentity } from "@supabase/supabase-js"; | ||
import { revalidatePath } from "next/cache"; | ||
import { redirect } from "next/navigation"; | ||
import { createSupabaseServerClient } from "utils/supabase/server"; | ||
|
||
type LinkIdentityState = { | ||
identity: UserIdentity | undefined; | ||
error: string; | ||
}; | ||
|
||
export async function linkIdentity( | ||
state: LinkIdentityState, | ||
provider: Provider, | ||
) { | ||
const supabase = createSupabaseServerClient(); | ||
|
||
if (state.identity) { | ||
const { error: unlinkError } = await supabase.auth.unlinkIdentity( | ||
state.identity, | ||
); | ||
|
||
if (unlinkError) { | ||
return { ...state, error: unlinkError.message }; | ||
} | ||
|
||
return { identity: undefined, error: "" }; | ||
} | ||
|
||
const { data: linkData, error: linkError } = await supabase.auth.linkIdentity( | ||
{ | ||
provider, | ||
options: { | ||
redirectTo: `${process.env.ORIGIN}/auth/callback?next=/settings/third-party-services`, | ||
}, | ||
}, | ||
); | ||
|
||
if (linkError) { | ||
return { ...state, error: linkError.message }; | ||
} | ||
|
||
revalidatePath("/", "layout"); | ||
redirect(linkData.url); | ||
} |
Oops, something went wrong.