Skip to content

Commit 25b8e19

Browse files
committed
Steve's website features
2 parents 699147e + 7c12dd4 commit 25b8e19

11 files changed

+542
-3062
lines changed

README.md

+44-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,58 @@
1-
### GT Web Dev Website
2-
Repo for new GT Web Dev website <br>
3-
Download Node.js (LTS is fine)
4-
https://nodejs.org/en/
1+
# GT Web Dev Website
52

3+
## About
4+
GT Web Dev website
5+
6+
## Requirements
7+
- [NodeJS 18.x](https://nodejs.org/en/)
8+
- Tip: install it using [nvm](https://github.com/nvm-sh/nvm) to easily manage versions
9+
10+
## Get Started
611
Clone Repo
712
```
813
git clone https://github.com/gt-webdev/gt-webdev-website
914
```
10-
Starting app
15+
Start the app
1116
```
12-
npm install (installs node modules we need)
17+
npm install
1318
npm run dev
1419
```
1520
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
1621

17-
The page will reload if you make edits.<br>
18-
You will also see any lint errors in the console.
22+
## How to Add Firebase API Credentials
23+
24+
Refer to [credentials document](https://docs.google.com/document/d/1tnGvafEfU0Iy-EnsLgH6mPMvDm984vUaa-Z_sLcSXMU/edit) for link to .env file
1925

20-
Stopping app
26+
Create `.env` file with following content (derived from Firebase Admin SDK JSON) and place the file in the root of the repository folder:
27+
28+
```shell
29+
firebase_type="..."
30+
firebase_project_id="..."
31+
firebase_private_key_id="..."
32+
firebase_private_key="..."
33+
firebase_client_email="..."
34+
firebase_client_id="..."
35+
firebase_auth_uri="..."
36+
firebase_token_uri="..."
37+
firebase_auth_provider_x509_cert_url="..."
38+
firebase_client_x509_cert_url="..."
2139
```
22-
Cntrl C
40+
41+
## How to Promote a Firebase User to Admin
42+
43+
Add Firebase credentials via .env file (mentioned above)
44+
45+
Then run the following command:
46+
47+
```shell
48+
node scripts/promote-to-admin.js user_uid
2349
```
2450

51+
The ID for a user can be found in Firebase:
52+
53+
![Firebase User ID Location](docs/firebase-user-id-location.png)
54+
55+
## How to Login as an Admin User
56+
57+
- Visit [http://localhost:3000/login](http://localhost:3000/login)
58+
- Enter the credentials for the [admin Firebase user account](https://docs.google.com/document/d/1tnGvafEfU0Iy-EnsLgH6mPMvDm984vUaa-Z_sLcSXMU/edit)

components/AdminNavBar.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React, {useEffect, useState} from 'react';
2+
import {
3+
AppBar,
4+
Button,
5+
Divider,
6+
Drawer,
7+
Hidden,
8+
IconButton,
9+
Toolbar
10+
} from "@mui/material";
11+
import {getAuth} from "firebase/auth";
12+
import firebaseApp from "../helpers/firebase";
13+
import {useRouter} from "next/router";
14+
15+
const AdminNavBar = () => {
16+
const [isLoggedIn, setIsLoggedIn] = useState(false);
17+
18+
const auth = getAuth(firebaseApp);
19+
const router = useRouter();
20+
21+
// check if user is admin - if they are not, then kick them out from this page
22+
useEffect(() => {
23+
if (auth) {
24+
auth.onAuthStateChanged((user) => {
25+
if (user) {
26+
setIsLoggedIn(true);
27+
} else if (!user) {
28+
setIsLoggedIn(false);
29+
}
30+
});
31+
}
32+
}, []);
33+
34+
return (
35+
<div>
36+
<AppBar position="static">
37+
<Toolbar>
38+
<img src="gt-webdev-logo.png" alt="GT WebDev" height="35" />
39+
{
40+
isLoggedIn &&
41+
<Button variant="text" style={{color: "white", marginLeft: "auto"}} onClick={() => {
42+
if (auth) {
43+
auth.signOut()
44+
.then(response => {
45+
router.push("/login");
46+
})
47+
.catch((error) => {
48+
alert('Unable to sign out.');
49+
});
50+
}
51+
}}>Sign Out</Button>
52+
}
53+
</Toolbar>
54+
</AppBar>
55+
</div>
56+
);
57+
}
58+
59+
export default AdminNavBar;

data/contactData.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ let adminContacts = [
1818

1919
let contactTitle = "Got a question? No worries, send us a message";
2020

21-
export {adminContacts, contactTitle};
21+
export {adminContacts, contactTitle};

docs/firebase-user-id-location.png

317 KB
Loading

helpers/firebase.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Import the functions you need from the SDKs you need
2+
import { initializeApp } from "firebase/app";
3+
// TODO: Add SDKs for Firebase products that you want to use
4+
// https://firebase.google.com/docs/web/setup#available-libraries
5+
6+
// Your web app's Firebase configuration
7+
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
8+
const firebaseConfig = {
9+
apiKey: "AIzaSyCS2s7GzBGZ4-yKJ_q4d-vdqDNZQpD8M70",
10+
authDomain: "gt-webdev-website.firebaseapp.com",
11+
projectId: "gt-webdev-website",
12+
storageBucket: "gt-webdev-website.appspot.com",
13+
messagingSenderId: "562784179730",
14+
appId: "1:562784179730:web:37e4b2c5ea06f7f5e26acb",
15+
measurementId: "G-1QX4LKFHCS"
16+
};
17+
18+
// Initialize Firebase
19+
const firebaseApp = initializeApp(firebaseConfig);
20+
21+
export default firebaseApp;

0 commit comments

Comments
 (0)