{"id":14968868,"url":"https://github.com/pixelmothman/nextjs-app-b2b-starter-supabase","last_synced_at":"2026-01-05T03:40:35.471Z","repository":{"id":241644149,"uuid":"799981810","full_name":"pixelmothman/nextjs-app-b2b-starter-supabase","owner":"pixelmothman","description":"What if we could use Supabase for B2B apps faster than ever.","archived":false,"fork":false,"pushed_at":"2024-07-18T19:40:29.000Z","size":378,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T15:53:26.174Z","etag":null,"topics":["nextjs","reactjs","supabase","supabase-auth","supabase-js","tailwindcss"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pixelmothman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-13T13:29:35.000Z","updated_at":"2024-07-18T19:40:33.000Z","dependencies_parsed_at":"2024-05-29T13:41:11.901Z","dependency_job_id":null,"html_url":"https://github.com/pixelmothman/nextjs-app-b2b-starter-supabase","commit_stats":null,"previous_names":["pixelmothman/nextjs-app-b2b-starter-supabase"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelmothman%2Fnextjs-app-b2b-starter-supabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelmothman%2Fnextjs-app-b2b-starter-supabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelmothman%2Fnextjs-app-b2b-starter-supabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelmothman%2Fnextjs-app-b2b-starter-supabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pixelmothman","download_url":"https://codeload.github.com/pixelmothman/nextjs-app-b2b-starter-supabase/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238264717,"owners_count":19443397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nextjs","reactjs","supabase","supabase-auth","supabase-js","tailwindcss"],"created_at":"2024-09-24T13:40:44.095Z","updated_at":"2025-10-26T05:30:51.742Z","avatar_url":"https://github.com/pixelmothman.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Image of app](public/pixelmothman-nextjs-app-b2b-starter-supabase-2.png)\n\n# ⚡️ pixelmothman/nextjs-app-b2b-starter-supabase\n\nThis template provides a starting point for building B2B web applications using Next.js, Typescript, Supabase, Zod, TailwindCSS, Radix-ui, React Hot Toast, and Phosphor Icons.\n\n## Powered by\n\n- ◽️ **Next.js**: a React framework for building full-stack web applications.\n- 🪖 **Typescript**: javascript with syntax for types.\n- 💾 **Supabase**: an open source platform that allows users to build production-grade applications with a Postgres database, Authentication, instant APIs, Realtime, Functions, Storage, and Vector embeddings.\n- ✨ **Zod**: TypeScript-first schema validation with static type inference.\n- 🧪 **TailwindCSS**: a utility-first CSS framework packed with classes that can be composed to build any design, directly in the markup.\n- 🏗️ **Radix-ui Primitives**: An open-source UI component library for building high-quality, accessible design systems and web apps.\n- 🔥 **React Hot Toast**: smoking hot React notifications.\n\n## Getting Started\n\n### 1. Environment Setup\n\nClone the repository and create a `.env.local` file in the root directory. Add the following environment variables with your specific values:\n\n```plaintext\nNEXT_PUBLIC_SUPABASE_URL=''\nNEXT_PUBLIC_SUPABASE_ANON_KEY=''\nSUPABASE_SERVICE_KEY=''\n```\n\n### 2. Supabase Setup\n\nCreate a new Supabase Project.\n\n#### 2.1 Create Tables\nSet up the following tables:\n\n- user_table\n- org_table\n- org_membership_table\n- org_to_delete_table\n\n```sql\n    -- user table\n    -- the created_at should come from the auth.users table\n    create table user_table (\n    user_id uuid references auth.users on delete cascade not null primary key,\n    user_email text not null,\n    user_name text,\n    user_email_status text default 'pending' not null,\n    updated_at timestamp with time zone,\n    created_at timestamp with time zone\n    );\n    alter table user_table enable row level security;\n\n    -- org table\n    create table org_table (\n    org_id uuid default gen_random_uuid () not null primary key,\n    org_name text not null,\n    org_users int4 default 1 not null,\n    org_user_exclusivity boolean not null default true,\n    updated_at timestamp with time zone,\n    created_at timestamp with time zone default now() not null\n    );\n    alter table org_table enable row level security;\n\n    -- org membership table\n    create table org_membership_table(\n    org_membership_id uuid default gen_random_uuid () not null primary key,\n    org_id uuid references public.org_table (org_id) on delete cascade not null,\n    user_id uuid references public.user_table (user_id) not null,\n    org_membership_role text not null default 'owner',\n    org_membership_status text not null default 'pending',\n    invited_by uuid references public.user_table (user_id) null,\n    created_at timestamp with time zone default now() not null\n    );\n    alter table org_membership_table enable row level security;\n\n    -- org to delete table\n    create table org_to_delete_table (\n        org_to_delete_id uuid not null default gen_random_uuid () primary key,\n        org_id uuid references public.org_table (org_id) on delete cascade not null,\n        triggered_by uuid references public.user_table (user_id) not null,\n        created_at timestamp with time zone not null default now()\n    );\n    alter table org_to_delete_table enable row level security;\n```\n\n#### 2.2 Create Triggers\nCreate the triggers to:\n\n- Create a profile entry when a new user signs up via Supabase Auth.\n- Automatically update a profile entry when a user confirms for the first time their email.\n- Automatically update a profile entry when a user updates their email up via Supabase Auth.\n\n```sql\n    -- This trigger automatically creates a profile entry when a new user signs up via Supabase Auth.\n    create or replace function public.handle_new_user()\n    returns trigger as $$\n    begin\n        insert into public.user_table (user_id, user_email, created_at, user_email_status)\n        values (new.id, new.email, new.created_at,\n        CASE\n            WHEN new.confirmed_at IS NULL THEN 'pending'\n        END);\n        return new;\n    end;\n    $$ language plpgsql security definer;\n    \n    create or replace trigger on_auth_user_created\n    after insert on auth.users\n    for each row execute procedure public.handle_new_user();\n\n\n    -- This trigger automatically updates a profile entry when a user confirms for the first time their email.\n    create or replace function public.handle_user_confirmed_email()\n    returns trigger as $$\n    begin\n        IF NEW.confirmed_at IS NOT NULL THEN\n            UPDATE public.user_table\n            SET user_email_status = 'confirmed'\n            WHERE user_id = NEW.id;\n            UPDATE public.org_membership_table\n            SET org_membership_status = 'confirmed'\n            WHERE user_id = NEW.id;\n        END IF;\n        RETURN NEW;\n    end;\n    $$ language plpgsql security definer;\n\n    create or replace trigger on_auth_user_confirmed_email\n    after update of confirmed_at on auth.users\n    for each row execute procedure public.handle_user_confirmed_email();\n\n    -- This trigger automatically updates a profile entry when a user updates their email up via Supabase Auth.\n    create or replace function public.handle_user_new_email() \n    returns trigger as $$\n    BEGIN\n        UPDATE public.user_table\n        SET user_email = NEW.email\n        WHERE user_id = NEW.id;\n        RETURN NEW;\n    END;\n    $$ language plpgsql security definer;\n\n    create trigger on_auth_user_email_updated\n    after update of email on auth.users \n    for each row execute procedure public.handle_user_new_email();\n```\n\n## Disclaimer\n\nThe instructions and guidelines provided in this document reflect the author's opinions and are offered for informational purposes only. Users should exercise their judgment in applying any practices described here.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixelmothman%2Fnextjs-app-b2b-starter-supabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpixelmothman%2Fnextjs-app-b2b-starter-supabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixelmothman%2Fnextjs-app-b2b-starter-supabase/lists"}