Skip to content

Commit

Permalink
Better supabase setup
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelshimeles committed Jun 25, 2024
1 parent f746d15 commit 1e6a95a
Show file tree
Hide file tree
Showing 41 changed files with 101 additions and 82 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## NextJS 14 Starter Template
## NextJS 14 Starter Template

## Tech Stack
NextJS 14 - Full Stack framework
NextJS 14 - Full Stack framework

TailwindCSS - CSS framework

Expand Down Expand Up @@ -37,9 +37,9 @@ NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/

WEBHOOK_SECRET=

NEXT_PUBLIC_SUPABASE_URL=
SUPABASE_URL=

NEXT_PUBLIC_SUPABASE_ANON_KEY=
SUPABASE_SECRET_KEY=

DATABASE_URL=

Expand Down
19 changes: 19 additions & 0 deletions app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { openai } from "@ai-sdk/openai";
import { currentUser } from "@clerk/nextjs/server";
import { convertToCoreMessages, streamText, tool } from "ai";
import { z } from "zod";
import { useTheme } from "next-themes";

export async function POST(req: Request) {
const { messages } = await req.json();
const user = await currentUser();
const { setTheme } = useTheme();

const system = `
You are tsafi ai, an ai assistant helping users of tsafi create and manager their blog sites and content.
Expand Down Expand Up @@ -60,6 +62,23 @@ export async function POST(req: Request) {
};
},
}),
toggleMode: {
description: `
Toggle between light, dark and system mode. Always call this tool when
the user asks to set the light, dark or system mode. Call this tool if
the user simply prompts "dark mode", "light mode" or "system mode". If
the user asks you to do anything else regarding this task, explain why
you can't do that.`,
parameters: z.object({
mode: z.enum(["light", "dark", "system"]),
}),
// execute: async (mode: any) => {
// setTheme(mode)
// return {
// message: "Mode changed"
// }
// },
},
},
onFinish: async ({ text, toolCalls, toolResults, finishReason, usage }) => {
console.log("toolResults", toolResults);
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/api/get-article-slug-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const getArticleBySlugApi = async (slug: string, userId: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/api/get-articles-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const getAllArticlesApi = async (userId: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/api/get-articles-slugs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const getArticlesSlugApi = async (userId: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/articles/create-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const createDocument = async (title: string, site_id: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/articles/delete-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const deleteDocument = async (id: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/articles/get-all-categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const getAllCategories = async (site_id: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/articles/get-all-documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const getAllDocuments = async () => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/articles/get-article-slug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const getAllArticleBySlug = async (slug: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/articles/get-document-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const getDocumentById = async (id: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/articles/read-public-article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const readPublicArticle = async (id: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/articles/share-article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const shareArticle = async (
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/articles/store-articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const storeArticles = async (
const keywordArray = keywords?.split(",");

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/articles/store-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const storeDocument = async (
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/articles/update-article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const updateArticle = async (slug: string, blog: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/author/create-author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const createAuthor = async (
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/author/get-all-authors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const getAllAuthors = async (site_id: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/blog/delete-blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const deleteBlog = async (slug: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/blog/status-publish-blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const statusBlogs = async (slug: string, published: boolean) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/category/create-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const createCategory = async (category: string, site_id: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/articles/read-article-slug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const readArticleSlug = async (slug: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/articles/read-articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export const readAllArticles = async (site_id: string) => {

// Initialize Supabase client
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/create-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const createSites = async (
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/delete-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const deleteSite = async (site_id: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/read-site-custom-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const readSiteCustomDomain = async (domain: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/read-site-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const readSiteDomain = async (domain: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/read-site-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const readSiteById = async (site_id: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/read-sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const readSites = async () => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/settings/change-site-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const changeSiteDescription = async (site_id: string, site_description: s
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/settings/change-site-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const changeSiteDomain = async (
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/settings/change-site-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const changeSiteName = async (site_id: string, site_name: string) => {
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/actions/sites/settings/change-site-subdomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const changeSiteSubdomain = async (site_id: string, site_subdomain: strin
const cookieStore = cookies();

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!,
{
cookies: {
get(name: string) {
Expand Down
Loading

0 comments on commit 1e6a95a

Please sign in to comment.