forked from ryan-parag/slack-themes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2f3260
commit 4e28ca2
Showing
18 changed files
with
902 additions
and
44 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
config.js | ||
.env | ||
.env.local | ||
secrets.json | ||
|
||
# Logs | ||
logs | ||
|
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
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,29 @@ | ||
import React, { useEffect, useState, useContext, createContext } from 'react' | ||
import nookies from "nookies" | ||
import {firebaseClient} from '../../data/firebase' | ||
import firebase from "firebase/app" | ||
import "firebase/auth" | ||
|
||
const AuthContext = createContext({}) | ||
|
||
export const AuthProvider = ({children}) => { | ||
firebaseClient() | ||
const [user, setUser] = useState(null) | ||
|
||
useEffect(() => { | ||
return firebase.auth().onIdTokenChanged(async (user) => { | ||
if(!user) { | ||
setUser(null) | ||
nookies.set(undefined, "token", '', {}) | ||
return | ||
} | ||
const token = await user.getIdToken() | ||
setUser(user) | ||
nookies.set(undefined, "token", token, {}) | ||
}) | ||
}, []) | ||
|
||
return (<AuthContext.Provider value={{user}}>{children}</AuthContext.Provider>) | ||
} | ||
|
||
export const useAuth = () => useContext(AuthContext) |
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
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,18 @@ | ||
const admin = require("firebase-admin") | ||
const serviceAccount = require("../data/service") | ||
|
||
export const verifyIdToken = (token) => { | ||
if(!admin.apps.length) { | ||
admin.initializeApp({ | ||
credential: admin.credential.cert(JSON.parse(JSON.stringify(serviceAccount))), | ||
databaseURL: process.env.DATABASE_URL, | ||
}) | ||
} | ||
|
||
return admin | ||
.auth() | ||
.verifyIdToken(token) | ||
.catch((error) => { | ||
throw error | ||
}) | ||
} |
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,12 @@ | ||
module.exports = { | ||
type: process.env.SERVICE_TYPE, | ||
project_id: process.env.SERVICE_PROJECT_ID, | ||
private_key_id: process.env.SERVICE_PRIVATE_KEY_ID, | ||
private_key: process.env.SERVICE_PRIVATE_KEY, | ||
client_email: process.env.SERVICE_CLIENT_EMAIL, | ||
client_id: process.env.SERVICE_CLIENT_ID, | ||
auth_uri: process.env.SERVICE_AUTH_URI, | ||
token_uri: process.env.SERVICE_TOKEN_URI, | ||
auth_provider_x509_cert_url: process.env.SERVICE_AUTH_PROVIDER_X509_CERT_URL, | ||
client_x509_cert_url: process.env.SERVICE_CLIENT_X509_CERT_URL | ||
} |
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
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,97 @@ | ||
import React, { useState } from "react" | ||
import nookies from "nookies" | ||
import {verifyIdToken} from "../data/admin" | ||
import {firebaseClient} from "../data/firebase" | ||
import firebase from "firebase/app" | ||
import Layout from '../components/Layout' | ||
import { ThemeHeader } from '../components/ThemeAdmin' | ||
import { motion } from 'framer-motion' | ||
import { Loader } from 'react-feather' | ||
|
||
function Dashboard({session}) { | ||
firebaseClient() | ||
const [activeTab, setActiveTab] = useState('themes') | ||
|
||
const signOut = async () => { | ||
await firebase.auth().signOut() | ||
window.location.href = '/login' | ||
} | ||
|
||
if(session) { | ||
return ( | ||
<Layout> | ||
<ThemeHeader loggedIn={signOut} /> | ||
<div className="border-b border-gray-300 flex w-full justify-center"> | ||
<div className="w-full md:w-1/2 mx-auto text-center"> | ||
<h1>Themes</h1> | ||
<p className="text-xl mt-4">Edit/Add themes in the database</p> | ||
<div className="flex border-b mt-8"> | ||
<button | ||
className={`transition w-full focus:outline-none text-center hover:bg-gray-100 p-3 ${activeTab === 'themes' ? 'font-bold border-b-2 border-current' : 'border-b border-transparent text-gray-600 hover:border-current'}`} | ||
onClick={() => setActiveTab('themes')} | ||
> | ||
Themes | ||
</button> | ||
<button | ||
className={`transition w-full focus:outline-none text-center hover:bg-gray-100 p-3 ${activeTab === 'submitted' ? 'font-bold border-b-2 border-current' : 'border-b border-transparent text-gray-600 hover:border-current focus:border-current'}`} | ||
onClick={() => setActiveTab('submitted')} | ||
> | ||
Submitted | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="py-8 px-4 md:px-0"> | ||
{ | ||
activeTab === 'themes' ? ( | ||
<div className="bg-pink-100 text-pink-900 p-8 rounded-md block text-center w-full"> | ||
THEMES TODO | ||
</div> | ||
) | ||
: | ||
null | ||
} | ||
{ | ||
activeTab === 'submitted' ? ( | ||
<div className="bg-yellow-100 text-yellow-900 p-8 rounded-md block text-center w-full"> | ||
SUBMITTED TODO | ||
</div> | ||
) | ||
: | ||
null | ||
} | ||
</div> | ||
</Layout> | ||
) | ||
} else { | ||
return ( | ||
<div className="rounded-md text-center bg-gray-100 p-8 mt-4"> | ||
<motion.div | ||
animate={{ rotate: 360 }} | ||
transition={{ ease: "linear", duration: 1, loop: Infinity }} | ||
className="inline-block p-3 mb-4 bg-gray-200 text-gray-800 rounded-full" | ||
> | ||
<Loader/> | ||
</motion.div> | ||
<h4>Loading...</h4> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export async function getServerSideProps(context) { | ||
try { | ||
const cookies = nookies.get(context) | ||
const token = await verifyIdToken(cookies.token) | ||
const {uid, email} = token | ||
return { | ||
props: { session: `Your email is ${email} and your UID is ${uid}`} | ||
} | ||
} catch (err) { | ||
context.res.writeHead(302, {location: "/login"}) | ||
context.res.end() | ||
return {props: []} | ||
} | ||
} | ||
|
||
export default Dashboard |
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.