Skip to content

Commit

Permalink
feat: add server supabase instance, improve naming, fix humans.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
wisnie committed Oct 21, 2022
1 parent 8c6fe02 commit 5ce99f1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_KEY=
SUPABASE_SECRET_KEY=
3 changes: 3 additions & 0 deletions lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
type KeyToType = {
NEXT_PUBLIC_SUPABASE_URL: string;
NEXT_PUBLIC_SUPABASE_KEY: string;
SUPABASE_SECRET_KEY: string;
};

type GetValue = <T extends keyof KeyToType>(key: T) => KeyToType[T] | null | undefined;
Expand All @@ -12,6 +13,8 @@ const getValue: GetValue = (key) => {
return process.env.NEXT_PUBLIC_SUPABASE_URL;
case 'NEXT_PUBLIC_SUPABASE_KEY':
return process.env.NEXT_PUBLIC_SUPABASE_KEY;
case 'SUPABASE_SECRET_KEY':
return process.env.SUPABASE_SECRET_KEY;
default:
return null;
}
Expand Down
12 changes: 0 additions & 12 deletions lib/post/createCommunity.ts

This file was deleted.

12 changes: 12 additions & 0 deletions lib/server/createCommunityServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Community } from '../../validators/Community';
import { serverSupabase } from '../serverSupabase';

export const createCommunityServer = async (fields: Community) => {
const { data, error } = await serverSupabase.from('Community').insert([fields]);

if (error) {
throw new Error(error.message);
}

return data;
};
7 changes: 7 additions & 0 deletions lib/serverSupabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createClient } from '@supabase/supabase-js';
import { getEnvValue } from './env';

export const serverSupabase = createClient(
getEnvValue('NEXT_PUBLIC_SUPABASE_URL'),
getEnvValue('SUPABASE_SECRET_KEY'),
);
4 changes: 2 additions & 2 deletions pages/api/communities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NextRequest } from 'next/server';
import slugify from 'slugify';
import { createCommunity } from '../../lib/post/createCommunity';
import { createCommunityServer } from '../../lib/server/createCommunityServer';
import { CommunityFieldsSch } from '../../validators/Community';

export const config = {
Expand All @@ -16,7 +16,7 @@ export default async function handler(req: NextRequest) {
const communityFields = CommunityFieldsSch.parse(json);

// throws error if bad data is provided
await createCommunity({ ...communityFields, slug: slugify(communityFields.name) });
await createCommunityServer({ ...communityFields, slug: slugify(communityFields.name) });

return new Response(null, {
status: 201,
Expand Down
2 changes: 1 addition & 1 deletion public/humans.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* TEAM */
Lead developer: Bartłomiej Wiśniewski
Contact: b.wisniewski128 [at] gmail.com
From: Świętokrzyskie, Poland
From: Świętokrzyskie, Poland

Developer: Michał Ołubiec
From: Świętokrzyskie, Poland
Expand Down

0 comments on commit 5ce99f1

Please sign in to comment.