Skip to content

Commit

Permalink
Bump next to v14.1 and deprecated next-auth-helpers in favor of @supa…
Browse files Browse the repository at this point in the history
…base/ssr
  • Loading branch information
Dosbodoke committed Jan 22, 2024
1 parent ee1b555 commit 37e36d1
Show file tree
Hide file tree
Showing 37 changed files with 973 additions and 443 deletions.
6 changes: 5 additions & 1 deletion app/[locale]/Providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ interface Props {
function Providers({ locale, messages, children }: Props) {
return (
<ReactQueryProvider>
<NextIntlClientProvider locale={locale} messages={messages}>
<NextIntlClientProvider
locale={locale}
messages={messages}
timeZone={"America/Sao_Paulo"}
>
<ThemeProvider attribute="class">{children}</ThemeProvider>
</NextIntlClientProvider>
</ReactQueryProvider>
Expand Down
6 changes: 5 additions & 1 deletion app/[locale]/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { cookies } from "next/headers";
import { notFound } from "next/navigation";

import HighlineImage from "@/components/HighlineImage";
import RegistryEntry from "@/components/RegistryEntry";
import Tabs from "@/components/tabs/Tabs";
import supabase from "@/utils/supabase";
import { useSupabaseServer } from "@/utils/supabase/server";

import GoBack from "./_components/GoBack";

Expand All @@ -14,6 +15,9 @@ export default async function Highline({
}: {
params: { id: string };
}) {
const cookieStore = cookies();
const supabase = useSupabaseServer(cookieStore);

const { data: highline } = await supabase
.from("highline")
.select()
Expand Down
9 changes: 3 additions & 6 deletions app/[locale]/_components/UsernameDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import {
createClientComponentClient,
User,
} from "@supabase/auth-helpers-nextjs";
import type { User } from "@supabase/supabase-js";
import { useTranslations } from "next-intl";
import { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
Expand All @@ -29,7 +26,7 @@ import {
} from "@/components/ui/Form";
import { Input } from "@/components/ui/Input";
import { useRouter } from "@/navigation";
import { Database } from "@/utils/database.types";
import useSupabaseBrowser from "@/utils/supabase/client";

const formSchema = z.object({
username: z
Expand All @@ -44,7 +41,7 @@ const formSchema = z.object({
type FormSchema = z.infer<typeof formSchema>;

export default function UsernameDialog() {
const supabase = createClientComponentClient<Database>();
const supabase = useSupabaseBrowser();

const t = useTranslations("usernameDialog");
const router = useRouter();
Expand Down
9 changes: 4 additions & 5 deletions app/[locale]/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Refer to the following documentation for more context
// https://supabase.com/docs/guides/auth/auth-helpers/nextjs#managing-sign-in-with-code-exchange

import { createRouteHandlerClient } from "@supabase/auth-helpers-nextjs";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";

import { Database } from "@/utils/database.types";
import { useSupabaseServer } from "@/utils/supabase/server";

export const dynamic = "force-dynamic";

Expand All @@ -18,9 +17,9 @@ export async function GET(request: Request) {

if (code) {
const cookieStore = cookies();
const supabase = createRouteHandlerClient<Database>({
cookies: () => cookieStore,
});
// eslint-disable-next-line react-hooks/rules-of-hooks
const supabase = useSupabaseServer(cookieStore);

await supabase.auth.exchangeCodeForSession(code);
}

Expand Down
8 changes: 2 additions & 6 deletions app/[locale]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { cookies } from "next/headers";
import { unstable_setRequestLocale } from "next-intl/server";

import Highline from "@/components/Highline";
import { Database } from "@/utils/database.types";
import { useSupabaseServer } from "@/utils/supabase/server";

import Search from "./_components/search";

Expand All @@ -17,9 +15,7 @@ export default async function Home({
searchParams?: { [key: string]: string | string[] | undefined };
}) {
const cookieStore = cookies();
const supabase = createServerComponentClient<Database>({
cookies: () => cookieStore,
});
const supabase = useSupabaseServer(cookieStore);

const { q: searchValue } = searchParams as {
[key: string]: string;
Expand Down
8 changes: 3 additions & 5 deletions app/[locale]/profile/[username]/_components/LastWalks.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChevronRightIcon } from "@radix-ui/react-icons";
import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { cookies } from "next/headers";
import Link from "next/link";
import { useTranslations } from "next-intl";
Expand All @@ -10,8 +9,9 @@ import {
PopoverContent,
PopoverTrigger,
} from "@/components/ui/Popover";
import { Database } from "@/utils/database.types";
import { transformSecondsToTimeString } from "@/utils/helperFunctions";
import type { Database } from "@/utils/supabase/database.types";
import { useSupabaseServer } from "@/utils/supabase/server";

import FormattedDate from "./FormattedDate";

Expand All @@ -23,9 +23,7 @@ interface Props {

export default async function LastWalks({ username }: Props) {
const cookieStore = cookies();
const supabase = createServerComponentClient<Database>({
cookies: () => cookieStore,
});
const supabase = useSupabaseServer(cookieStore);

const { data: entries } = await supabase
.from("entry")
Expand Down
4 changes: 2 additions & 2 deletions app/[locale]/profile/[username]/_components/UserHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { User } from "@supabase/auth-helpers-nextjs";
import { User } from "@supabase/supabase-js";
import Image from "next/image";
import { useTranslations } from "next-intl";

import UpdateProfile from "@/components/layout/navbar/UpdateProfile";
import { Database } from "@/utils/database.types";
import { Database } from "@/utils/supabase/database.types";

interface Props {
user: User | null;
Expand Down
7 changes: 2 additions & 5 deletions app/[locale]/profile/[username]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import type { Metadata, ResolvingMetadata } from "next";
import { cookies } from "next/headers";
import { getTranslations } from "next-intl/server";
import { Suspense } from "react";

import { Database } from "@/utils/database.types";
import { useSupabaseServer } from "@/utils/supabase/server";

import GoBack from "./_components/GoBack";
import LastWalks, { LastWalksSkeleton } from "./_components/LastWalks";
Expand Down Expand Up @@ -32,9 +31,7 @@ export async function generateMetadata(

export default async function Profile({ params: { username } }: Props) {
const cookieStore = cookies();
const supabase = createServerComponentClient<Database>({
cookies: () => cookieStore,
});
const supabase = useSupabaseServer(cookieStore);

const {
data: { user },
Expand Down
7 changes: 5 additions & 2 deletions components/CreateHighline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { z } from "zod";

import { PlusSvg } from "@/assets";
import { Link } from "@/navigation";
import supabase, {
import useSupabaseBrowser from "@/utils/supabase/client";
import {
ACCEPTED_IMAGE_TYPES,
MAX_FILE_SIZE,
} from "@/utils/supabase";
} from "@/utils/supabase/constants";

import { SuccessAnimation } from "./animations/SuccessAnimation";
import Button from "./ui/Button";
Expand Down Expand Up @@ -66,6 +67,8 @@ const formSchema = z.object({
type FormSchema = z.infer<typeof formSchema>;

const CreateHighline = () => {
const supabase = useSupabaseBrowser();

const t = useTranslations("home.newHighline");
const [dialogOpen, setDialogOpen] = useState(false);
const [newHighlineUUID, setNewHighlineUUID] = useState<string | null>(null);
Expand Down
2 changes: 1 addition & 1 deletion components/Highline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useTranslations } from "next-intl";

import { ArrowIcon } from "@/assets";
import { Link } from "@/navigation";
import type { Tables } from "@/utils/supabase";
import type { Tables } from "@/utils/supabase/database.types";

import HighlineImage from "./HighlineImage";

Expand Down
5 changes: 3 additions & 2 deletions components/RegistryEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { z } from "zod";

import { PlusSvg } from "@/assets";
import { transformTimeStringToSeconds } from "@/utils/helperFunctions";
import supabase from "@/utils/supabase";
import useSupabaseBrowser from "@/utils/supabase/client";

import { SuccessAnimation } from "./animations/SuccessAnimation";
import Button from "./ui/Button";
Expand Down Expand Up @@ -73,8 +73,9 @@ interface Props {
}

const CreateHighline = ({ highlineId, highlineDistance }: Props) => {
const [dialogOpen, setDialogOpen] = useState(false);
const supabase = useSupabaseBrowser();

const [dialogOpen, setDialogOpen] = useState(false);
const t = useTranslations("highline.registry");
const queryClient = useQueryClient();

Expand Down
56 changes: 26 additions & 30 deletions components/layout/navbar/ProfileMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { cookies } from "next/headers";
"use client";

import { User } from "@supabase/supabase-js";
import { useTranslations } from "next-intl";

import { UserCircleIcon } from "@/assets";
import { LogOutIcon, UserCircleIcon } from "@/assets";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/DropdownMenu";
import { Link } from "@/navigation";
import { Link, useRouter } from "@/navigation";
import useSupabaseBrowser from "@/utils/supabase/client";

import SignOut from "./SignOut";
import UpdateProfile from "./UpdateProfile";
export default async function ProfileMenu({ user }: { user: User }) {
const supabase = useSupabaseBrowser();
const t = useTranslations("profileMenu");
const router = useRouter();

export default async function ProfileMenu() {
const cookieStore = cookies();
const supabase = createServerComponentClient({
cookies: () => cookieStore,
});
const username: string | null = user.user_metadata["username"];

const {
data: { user },
} = await supabase.auth.getUser();
const signOut = async () => {
await supabase.auth.signOut();
router.refresh();
};

return (
<DropdownMenu>
Expand All @@ -38,24 +39,19 @@ export default async function ProfileMenu() {
sideOffset={8}
className="max-w-[12rem] overflow-hidden"
>
<ProfileSection username={user?.user_metadata["username"]} />
{username ? (
<DropdownMenuItem asChild>
<Link href={`/profile/${username.replace("@", "")}`}>
{t("myProfile")}
</Link>
</DropdownMenuItem>
) : null}
<DropdownMenuSeparator />
<SignOut />
<DropdownMenuItem className="flex justify-between" onClick={signOut}>
<span>{t("signOut")}</span>
<LogOutIcon className="h-4 w-4 dark:text-white" />
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
}

function ProfileSection({ username }: { username: string | null }) {
const t = useTranslations("profileMenu");

if (!username) return null;

return (
<DropdownMenuItem asChild>
<Link href={`/profile/${username.replace("@", "")}`}>
{t("myProfile")}
</Link>
</DropdownMenuItem>
);
}
27 changes: 0 additions & 27 deletions components/layout/navbar/SignOut.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion components/layout/navbar/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
FormMessage,
} from "@/components/ui/Form";
import { Input } from "@/components/ui/Input";
import supabase from "@/utils/supabase";
import useSupabaseBrowser from "@/utils/supabase/client";

const formSchema = z.object({
email: z.string().email(),
Expand All @@ -34,6 +34,7 @@ const formSchema = z.object({
type FormSchema = z.infer<typeof formSchema>;

function SignUp() {
const supabase = useSupabaseBrowser();
const t = useTranslations();
const [step, setStep] = useState<"initial" | "email" | "inbox">("initial");
const form = useForm<FormSchema>({
Expand Down
10 changes: 4 additions & 6 deletions components/layout/navbar/UpdateProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import {
createClientComponentClient,
User,
} from "@supabase/auth-helpers-nextjs";
import type { User } from "@supabase/supabase-js";
import { useMutation } from "@tanstack/react-query";
import { useTranslations } from "next-intl";
import { useState } from "react";
Expand All @@ -29,7 +26,8 @@ import {
import { Input } from "@/components/ui/Input";
import { TextArea } from "@/components/ui/TextArea";
import { useRouter } from "@/navigation";
import { Database } from "@/utils/database.types";
import useSupabaseBrowser from "@/utils/supabase/client";
import { Database } from "@/utils/supabase/database.types";

const formSchema = z.object({
name: z.string().min(3, "Deve conter ao menos 3 caracteres"),
Expand All @@ -49,7 +47,7 @@ export default function UpdateProfile({

const t = useTranslations("updateProfile");
const router = useRouter();
const supabase = createClientComponentClient<Database>();
const supabase = useSupabaseBrowser();
const profileForm = useForm<FormSchema>({
mode: "onTouched",
resolver: zodResolver(formSchema),
Expand Down
Loading

0 comments on commit 37e36d1

Please sign in to comment.