Skip to content

Commit a8e0aac

Browse files
committed
feat: add firebase for the backend
1 parent 6ad5244 commit a8e0aac

8 files changed

+66
-2
lines changed

.env.development

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Dev URL
2-
NEXT_PUBLIC_URL=YOUR_DEV_URL
2+
NEXT_PUBLIC_URL=
3+
4+
# Owner Secret
5+
NEXT_PUBLIC_OWNER_BEARER_TOKEN=
6+
7+
# Firebase
8+
API_KEY=
9+
AUTH_DOMAIN=
10+
PROJECT_ID=
11+
STORAGE_BUCKET=
12+
MESSAGING_SENDER_ID=
13+
APP_ID=
314

415
# GitHub
5-
GITHUB_TOKEN=YOUR_GITHUB_TOKEN
16+
GITHUB_TOKEN=

.firebaserc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "portofolio-ccrsxx"
4+
}
5+
}

firebase.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"firestore": {
3+
"rules": "firestore.rules",
4+
"indexes": "firestore.indexes.json"
5+
}
6+
}

firestore.indexes.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"indexes": [],
3+
"fieldOverrides": []
4+
}

firestore.rules

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
rules_version = '2';
2+
service cloud.firestore {
3+
match /databases/{database}/documents {
4+
match /{document=**} {
5+
allow read, write: if true;
6+
}
7+
}
8+
}

src/lib/firebase/app.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { initializeApp } from 'firebase/app';
2+
import { getFirestore } from 'firebase/firestore';
3+
import { getFirebaseConfig } from './config';
4+
5+
initializeApp(getFirebaseConfig());
6+
7+
export const db = getFirestore();

src/lib/firebase/collections.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { collection } from 'firebase/firestore';
2+
import { contentMetaConverter } from '@lib/types/meta';
3+
import { db } from './app';
4+
5+
export const contentsCollection = collection(db, 'contents').withConverter(
6+
contentMetaConverter
7+
);

src/lib/firebase/config.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const config = {
2+
apiKey: process.env.API_KEY,
3+
authDomain: process.env.AUTH_DOMAIN,
4+
projectId: process.env.PROJECT_ID,
5+
storageBucket: process.env.STORAGE_BUCKET,
6+
messagingSenderId: process.env.MESSAGING_SENDER_ID,
7+
appId: process.env.APP_ID
8+
};
9+
10+
type Config = typeof config;
11+
12+
export function getFirebaseConfig(): Config {
13+
if (Object.values(config).some((value) => !value))
14+
throw new Error('Firebase config is not set or incomplete');
15+
return config;
16+
}

0 commit comments

Comments
 (0)