-
-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented firebase
- Loading branch information
Showing
9 changed files
with
2,765 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import admin from 'firebase-admin'; | ||
import { promises as fs } from 'fs'; | ||
import path from 'path'; | ||
import { NextResponse } from 'next/server'; | ||
import { customInitApp } from 'lib/firebase-admin-config'; | ||
|
||
customInitApp(); | ||
|
||
const folders = [ | ||
'BlockChain', | ||
'DSA', | ||
'artificial_intelligence', | ||
'backend', | ||
'cloud_computing_platforms', | ||
'competitive_programming', | ||
'cybersecurity', | ||
'data_structures', | ||
'devops', | ||
'frontend', | ||
'internet_of_things', | ||
'languages', | ||
'open_source', | ||
'other', | ||
'placement_prep', | ||
'resources', | ||
'technical-writing', | ||
'youtube' | ||
]; | ||
|
||
export async function GET() { | ||
try { | ||
const firestore = admin.firestore(); | ||
const mainDirectoryPath = path.join(__dirname, '../../../../database'); | ||
for (let i = 0; i < folders.length; i++) { | ||
const folder = folders[i]; | ||
const folderPath = path.join(mainDirectoryPath, folder); | ||
|
||
const files = await fs.readdir(folderPath); | ||
for (let j = 0; j < files.length; j++) { | ||
const file = files[j]; | ||
const filePath = path.join(folderPath, file); | ||
|
||
const fileContent = await fs.readFile(filePath, 'utf-8'); | ||
const jsonData = JSON.parse(fileContent); | ||
console.log(jsonData); | ||
firestore.collection('resources').doc(folder).set({ resources: jsonData }); | ||
} | ||
} | ||
return NextResponse.json({ message: 'Imported to Firestore' }); | ||
} catch (error) { | ||
console.error('Error occurred: \n', error); | ||
return NextResponse.json({ message: 'Error occurred' }); | ||
} | ||
} |
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,14 @@ | ||
import admin from 'firebase-admin' | ||
import { initializeApp, cert, getApps } from 'firebase-admin/app' | ||
import { serviceAccount } from '../service-account' | ||
|
||
const firebaseAdminConfig = { | ||
credential: cert(serviceAccount as admin.ServiceAccount), | ||
databaseURL: 'https://linkshub-3c1b9-default-rtdb.firebaseio.com', | ||
} | ||
|
||
export function customInitApp() { | ||
if (!getApps().length) { | ||
initializeApp(firebaseAdminConfig) | ||
} | ||
} |
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,20 @@ | ||
import { getAuth, GithubAuthProvider } from 'firebase/auth' | ||
import { initializeApp, getApps } from 'firebase/app' | ||
import { getFirestore } from 'firebase/firestore' | ||
|
||
const firebaseConfig = { | ||
apiKey: process.env.NEXT_FIREBASE_API_KEY, | ||
authDomain: process.env.NEXT_FIREBASE_AUTH_DOMAIN, | ||
projectId: process.env.NEXT_FIREBASE_PROJECT_ID, | ||
storageBucket: process.env.NEXT_FIREBASE_STORAGE_BUCKET, | ||
messagingSenderId: process.env.NEXT_FIREBASE_MESSAGING_SENDER_ID, | ||
appId: process.env.NEXT_FIREBASE_APP_ID, | ||
} | ||
|
||
const app = | ||
getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0] | ||
const db = getFirestore(app) | ||
const auth = getAuth(app) | ||
const provider = new GithubAuthProvider() | ||
// console.log(app); | ||
export { app, db, auth, provider, firebaseConfig } |
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
Oops, something went wrong.