-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move to server actions and new auth helpers BREAKING CHANGE: implicit auth -> pkce
- Loading branch information
1 parent
bd1b249
commit 4bc69f6
Showing
79 changed files
with
2,878 additions
and
182,922 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <reference types="next/navigation-types/navigation" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
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,7 @@ | ||
export default { | ||
experimental: { | ||
appDir: true, | ||
serverActions: true, | ||
}, | ||
images: { | ||
remotePatterns: [ | ||
|
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,48 @@ | ||
'use server'; | ||
|
||
import { createSupabaseServerActionClient } from '@/supabase-clients/createSupabaseServerActionClient'; | ||
import { | ||
deleteItem, | ||
getAllItems, | ||
getItem, | ||
insertItem, | ||
updateItem, | ||
} from '../utils/supabase-queries'; | ||
import { revalidatePath } from 'next/cache'; | ||
|
||
export async function insertItemAction(payload: { | ||
name: string; | ||
description: string; | ||
}) { | ||
const supabaseClient = createSupabaseServerActionClient(); | ||
const data = await insertItem(supabaseClient, payload); | ||
revalidatePath('/'); | ||
return data.id; | ||
} | ||
|
||
export async function getAllItemsAction() { | ||
const supabaseClient = createSupabaseServerActionClient(); | ||
return await getAllItems(supabaseClient); | ||
} | ||
|
||
export async function getItemAction(id: string) { | ||
const supabaseClient = createSupabaseServerActionClient(); | ||
return await getItem(supabaseClient, id); | ||
} | ||
|
||
export async function updateItemAction(payload: { | ||
id: string; | ||
name: string; | ||
description: string; | ||
}) { | ||
const supabaseClient = createSupabaseServerActionClient(); | ||
const data = await updateItem(supabaseClient, payload); | ||
revalidatePath('/'); | ||
return data; | ||
} | ||
|
||
export const deleteItemAction = async (id: string) => { | ||
const supabaseClient = createSupabaseServerActionClient(); | ||
await deleteItem(supabaseClient, id); | ||
revalidatePath('/'); | ||
}; |
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 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,93 @@ | ||
'use client'; | ||
import { Button } from '@/components/ui/Button'; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from '@/components/ui/Dialog'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useRouter } from 'next/navigation'; | ||
import { useRef, useState } from 'react'; | ||
import { toast } from 'react-hot-toast'; | ||
import Trash from 'lucide-react/dist/esm/icons/trash'; | ||
|
||
type Props = { | ||
itemId: string; | ||
deleteItemAction: (itemId: string) => Promise<void>; | ||
}; | ||
|
||
export const ConfirmDeleteItemDialog = ({ | ||
itemId, | ||
deleteItemAction, | ||
}: Props) => { | ||
const [open, setOpen] = useState(false); | ||
const toastRef = useRef<string | null>(null); | ||
const router = useRouter(); | ||
const { mutate, isLoading } = useMutation( | ||
async (id: string) => { | ||
return deleteItemAction(id); | ||
}, | ||
{ | ||
onMutate: () => { | ||
const toastId = toast.loading('Deleting item'); | ||
toastRef.current = toastId; | ||
}, | ||
onSuccess: () => { | ||
toast.success('Item deleted', { id: toastRef.current }); | ||
toastRef.current = null; | ||
router.refresh(); | ||
router.push('/'); | ||
}, | ||
onError: () => { | ||
toast.error('Failed to delete item', { id: toastRef.current }); | ||
toastRef.current = null; | ||
}, | ||
onSettled: () => { | ||
setOpen(false); | ||
}, | ||
} | ||
); | ||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<DialogTrigger asChild> | ||
<Button variant="destructive"> | ||
<Trash className="mr-1" /> Delete Item | ||
</Button> | ||
</DialogTrigger> | ||
<DialogContent className="sm:max-w-[425px]"> | ||
<DialogHeader> | ||
<DialogTitle>Delete Item</DialogTitle> | ||
<DialogDescription> | ||
Are you sure you want to delete this item? | ||
</DialogDescription> | ||
</DialogHeader> | ||
<DialogFooter> | ||
<Button | ||
type="button" | ||
variant="destructive" | ||
disabled={isLoading} | ||
onClick={() => { | ||
mutate(itemId); | ||
}} | ||
> | ||
{isLoading ? `Deleting item...` : `Yes, delete`} | ||
</Button> | ||
<Button | ||
disabled={isLoading} | ||
type="button" | ||
variant="outline" | ||
onClick={() => { | ||
setOpen(false); | ||
}} | ||
> | ||
Cancel | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
Oops, something went wrong.