Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
318 changes: 318 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,318 @@
# T// FILE: README.md
# Firebase React Full App (Single Copy/Paste)

This repository contains a minimal React app configured to run entirely on Firebase: Authentication (Email/Password + Google), Firestore (simple notes collection), and Hosting — ready for one-command deploy.

## Quick steps (summary)
2. Create a Firebase project in the Firebase Console.
3. Replace the Firebase config in `src/firebaseConfig.js` with your project's values (or set env variables for production).
4. Login to Firebase CLI: `firebase login`
5. Initialize (only once if not already): `firebase init` — choose Hosting, Firestore, and (optional) Functions if you want server code.
6. Build & deploy: `npm run build && firebase deploy --only hosting`

Full instructions are in the file `DEPLOY_INSTRUCTIONS.md` in this repo.

---

// FILE: DEPLOY_INSTRUCTIONS.md
# Deploy Instructions (Detailed)

1. Install Node.js (16+) and npm/yarn.
2. From project root: `npm install`.
3. Create a Firebase project at https://console.firebase.google.com/ and note the config values.
4. Open `src/firebaseConfig.js` and paste your config object (replace placeholders) OR set environment variables and use them.
5. Install Firebase CLI if you don't have it: `npm install -g firebase-tools`.
6. Login: `firebase login`.
7. Initialize (only if you haven't): `firebase init`.
- Choose **Hosting** and **Firestore**.
- For Hosting: set `build` as the public directory (the build output from `npm run build`).
- Configure as single-page app? Yes (rewrite all URLs to /index.html).
8. Build and Deploy:
```bash
npm run build
firebase deploy --only hosting
```

Notes:
- If you want to use Firebase Functions later (for server-side logic), re-run `firebase init functions` and move any server code to `functions/`.

---

// FILE: package.json
{
"name": "firebase-react-full-app",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"dependencies": {
"firebase": "^9.23.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1"
}
}

// FILE: .gitignore
node_modules/
build/
.env
/.firebase

// FILE: firebase.json
{
"hosting": {
"public": "build",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}

// FILE: .firebaserc
{
"projects": {
"default": "YOUR_FIREBASE_PROJECT_ID"
}
}

// FILE: public/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Firebase React Full App</title>
</head>
<body>
<div id="root"></div>
</body>
</html>

// FILE: src/index.js
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';
import './index.css';

const container = document.getElementById('root');
const root = createRoot(container);
root.render(<App />);

// FILE: src/index.css
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial; margin:0; padding:0; }
.app { padding: 20px; max-width: 800px; margin: 0 auto; }
.header { display:flex; justify-content:space-between; align-items:center; }
.card { border:1px solid #ddd; padding:16px; border-radius:8px; margin-top:12px }
input, textarea { width:100%; padding:8px; margin-top:8px; box-sizing:border-box }
button { padding:8px 12px; margin-top:8px }

// FILE: src/firebaseConfig.js
// Replace the placeholder values below with your Firebase project's config.
// You can also load them from environment variables if deploying with CI.

const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_PROJECT.firebaseapp.com",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_PROJECT.appspot.com",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID"
};

export default firebaseConfig;

// FILE: src/firebaseClient.js
import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';
import firebaseConfig from './firebaseConfig';

const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const db = getFirestore(app);

// FILE: src/App.js
import React, { useState } from 'react';
import Auth from './components/Auth';
import Notes from './components/Notes';
import { auth } from './firebaseClient';

export default function App(){
const [user, setUser] = useState(null);

// Simple listener (keeps UI minimal)
auth.onAuthStateChanged((u) => setUser(u));

return (
<div className="app">
<div className="header">
<h1>Firebase All-in-One App</h1>
{user ? <div>Welcome, {user.email}</div> : <div>Not signed in</div>}
</div>

<div className="card">
<Auth />
</div>

{user && (
<div className="card">
<Notes user={user} />
</div>
)}
</div>
);
}

// FILE: src/components/Auth.js
import React, { useState } from 'react';
import { auth } from '../firebaseClient';
import { createUserWithEmailAndPassword, signInWithEmailAndPassword, signOut, GoogleAuthProvider, signInWithPopup } from 'firebase/auth';

export default function Auth(){
const [mode, setMode] = useState('login');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');

async function handleEmailAuth(e){
e.preventDefault();
setError('');
try{
if(mode === 'login'){
await signInWithEmailAndPassword(auth, email, password);
} else {
await createUserWithEmailAndPassword(auth, email, password);
}
}catch(err){
setError(err.message);
}
}

async function handleGoogle(){
const provider = new GoogleAuthProvider();
try{
await signInWithPopup(auth, provider);
}catch(err){ setError(err.message); }
}

function handleSignOut(){ signOut(auth); }

return (
<div>
<h2>{mode === 'login' ? 'Sign In' : 'Create Account'}</h2>
<form onSubmit={handleEmailAuth}>
<input placeholder="Email" value={email} onChange={e=>setEmail(e.target.value)} />
<input placeholder="Password" type="password" value={password} onChange={e=>setPassword(e.target.value)} />
<button type="submit">{mode === 'login' ? 'Login' : 'Sign Up'}</button>
</form>

<div style={{marginTop:8}}>
<button onClick={handleGoogle}>Continue with Google</button>
</div>

<div style={{marginTop:8}}>
<button onClick={()=>setMode(mode === 'login' ? 'signup' : 'login')}>{mode === 'login' ? 'Need an account?' : 'Have an account?'}</button>
</div>

<div style={{marginTop:8}}>
<button onClick={handleSignOut}>Sign out</button>
</div>

{error && <div style={{color:'red'}}>{error}</div>}
</div>
);
}

// FILE: src/components/Notes.js
import React, { useEffect, useState } from 'react';
import { db } from '../firebaseClient';
import { collection, addDoc, query, where, onSnapshot, orderBy, deleteDoc, doc } from 'firebase/firestore';

export default function Notes({ user }){
const [text, setText] = useState('');
const [notes, setNotes] = useState([]);

useEffect(()=>{
if(!user) return;
const q = query(collection(db, 'notes'), where('uid', '==', user.uid), orderBy('createdAt', 'desc'));
const unsub = onSnapshot(q, (snap)=>{
const arr = [];
snap.forEach(d => arr.push({ id: d.id, ...d.data() }));
setNotes(arr);
});
return ()=>unsub();
}, [user]);

async function addNote(){
if(!text.trim()) return;
await addDoc(collection(db, 'notes'), { uid: user.uid, text: text.trim(), createdAt: Date.now() });
setText('');
}

async function removeNote(id){
await deleteDoc(doc(db, 'notes', id));
}

return (
<div>
<h3>Your Notes</h3>
<textarea rows={3} placeholder="Write a quick note" value={text} onChange={e=>setText(e.target.value)} />
<div>
<button onClick={addNote}>Add Note</button>
</div>

<div style={{marginTop:12}}>
{notes.length === 0 && <div>No notes yet</div>}
{notes.map(n => (
<div key={n.id} style={{border:'1px solid #eee', padding:8, borderRadius:6, marginTop:8}}>
<div>{n.text}</div>
<div style={{fontSize:12, color:'#666'}}>Created: {new Date(n.createdAt).toLocaleString()}</div>
<button onClick={()=>removeNote(n.id)}>Delete</button>
</div>
))}
</div>
</div>
);
}

// FILE: src/setupProxy.js
// (Optional) If you need to proxy API requests locally during development, add definitions here.

// END OF PROJECT
his workflow will build a golang project
$ cargo run --bin quiche-client -- https://cloudflare-quic.com/# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...