Phase 1 scaffold: auth for all apps
- Backend: Fastify with two listeners (public + internal), routes, services, DB migration + seed - client_app: Flutter with BLoC, all auth screens (welcome, display name, register, OTP, force-register) - mitra_app: Flutter with BLoC, OTP-only login - control_center: React + Vite, email/password login, mitra/user management, anonymity settings - Docs: phase1 plan, API contract, client app mockup - CLAUDE.md and shared memory for all subprojects Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
15
control_center/src/core/api/api-client.js
Normal file
15
control_center/src/core/api/api-client.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import axios from 'axios'
|
||||
import { auth } from '../auth/firebase'
|
||||
|
||||
export const apiClient = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL,
|
||||
})
|
||||
|
||||
apiClient.interceptors.request.use(async (config) => {
|
||||
const user = auth.currentUser
|
||||
if (user) {
|
||||
const token = await user.getIdToken()
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
})
|
||||
40
control_center/src/core/auth/AuthContext.jsx
Normal file
40
control_center/src/core/auth/AuthContext.jsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { createContext, useContext, useEffect, useState } from 'react'
|
||||
import { signInWithEmailAndPassword, signOut, onAuthStateChanged } from 'firebase/auth'
|
||||
import { auth } from './firebase'
|
||||
import { apiClient } from '../api/api-client'
|
||||
|
||||
const AuthContext = createContext(null)
|
||||
|
||||
export const AuthProvider = ({ children }) => {
|
||||
const [user, setUser] = useState(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
const unsub = onAuthStateChanged(auth, async (firebaseUser) => {
|
||||
if (firebaseUser) {
|
||||
try {
|
||||
const res = await apiClient.post('/internal/auth/verify')
|
||||
setUser(res.data.data)
|
||||
} catch {
|
||||
await signOut(auth)
|
||||
setUser(null)
|
||||
}
|
||||
} else {
|
||||
setUser(null)
|
||||
}
|
||||
setLoading(false)
|
||||
})
|
||||
return unsub
|
||||
}, [])
|
||||
|
||||
const login = (email, password) => signInWithEmailAndPassword(auth, email, password)
|
||||
const logout = () => signOut(auth)
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{ user, loading, login, logout }}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useAuth = () => useContext(AuthContext)
|
||||
11
control_center/src/core/auth/firebase.js
Normal file
11
control_center/src/core/auth/firebase.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { initializeApp } from 'firebase/app'
|
||||
import { getAuth } from 'firebase/auth'
|
||||
|
||||
const firebaseConfig = {
|
||||
apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
|
||||
authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
|
||||
projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
|
||||
}
|
||||
|
||||
const app = initializeApp(firebaseConfig)
|
||||
export const auth = getAuth(app)
|
||||
Reference in New Issue
Block a user