Skip to content

Commit

Permalink
feat: added firebase auth integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayantan-s committed Jul 10, 2024
1 parent 85b28bc commit f1a72ea
Show file tree
Hide file tree
Showing 16 changed files with 543 additions and 535 deletions.
414 changes: 413 additions & 1 deletion api/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pydantic = {extras = ["email"], version = "^2.7.4"}
gunicorn = "^22.0.0"
peewee = "^3.17.6"
psycopg2-binary = "^2.9.9"
firebase-admin = "^6.5.0"


[build-system]
Expand Down
1 change: 0 additions & 1 deletion api/services/meeting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from integrations.meetings.zoom import ZoomMeeting
from typing import Dict, Union
from db.models.meeting import Meeting

class MeetingService:
__meeting_provider_instance: Dict[str, Union[ZoomMeeting, GmeetMeeting]] = {
"zoom": ZoomMeeting,
Expand Down
Binary file added client/bun.lockb
Binary file not shown.
6 changes: 5 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
"preview": "rsbuild preview"
},
"dependencies": {
"@tanstack/react-query": "^5.50.1",
"@tanstack/react-query-devtools": "^5.50.1",
"firebase": "^10.12.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-components": "^6.1.11",
"styled-theming": "^2.2.0"
"styled-theming": "^2.2.0",
"zustand": "^4.5.4"
},
"devDependencies": {
"@biomejs/biome": "^1.8.1",
Expand Down
3 changes: 3 additions & 0 deletions client/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { pluginReact } from "@rsbuild/plugin-react";
import { pluginStyledComponents } from "@rsbuild/plugin-styled-components";

export default defineConfig({
dev: {
assetPrefix: true,
},
plugins: [
pluginReact(),
pluginStyledComponents({
Expand Down
5 changes: 5 additions & 0 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { useAuth } from "./store/auth";

const App = () => {
const { googleLogin } = useAuth();

return (
<div>
<h1>Rsbuild with React</h1>
<p>Start building amazing things with Rsbuild.</p>
<button onClick={googleLogin}>Google Login</button>
</div>
);
};
Expand Down
21 changes: 21 additions & 0 deletions client/src/apis/useGoogleLogin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useQueryClient } from "@tanstack/react-query";
import { GoogleAuthProvider, signInWithPopup } from "firebase/auth";
import Firebase from "../integrations/firebase";

export const GOOGLE_LOGIN_Q_KEY = "GOOGLE_LOGIN_Q_KEY" as const;

export const useGoogleLogin = () => {
const queryClient = useQueryClient();
return () =>
queryClient.ensureQueryData({
queryKey: [GOOGLE_LOGIN_Q_KEY],
queryFn: async () => {
const res = await signInWithPopup(
Firebase.auth,
new GoogleAuthProvider()
);
const token = await res.user.getIdToken();
console.log(token);
},
});
};
8 changes: 8 additions & 0 deletions client/src/constants/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const {
FIREBASE_API_KEY,
FIREBASE_APP_ID,
FIREBASE_AUTH_DOMAIN,
FIREBASE_MEASUREMENT_ID,
FIREBASE_MESSAGE_SENDER_ID,
FIREBASE_PROJECT_ID,
} = process.env;
13 changes: 13 additions & 0 deletions client/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
/// <reference types="@rsbuild/core/types" />

interface ImportMetaEnv {
readonly FIREBASE_API_KEY: string;
readonly FIREBASE_AUTH_DOMAIN: string;
readonly FIREBASE_PROJECT_ID: string;
readonly FIREBASE_MESSAGE_SENDER_ID: string;
readonly FIREBASE_APP_ID: string;
readonly FIREBASE_MEASUREMENT_ID: string;
}

interface ImportMeta {
readonly env: ImportMetaEnv;
}
10 changes: 7 additions & 3 deletions client/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import { NetworkConnection } from "./integrations/network";
import { Theme } from "./theme";

const rootEl = document.getElementById("root");

if (rootEl) {
const root = ReactDOM.createRoot(rootEl);
root.render(
<React.StrictMode>
<Theme>
<App />
</Theme>
<NetworkConnection>
<Theme>
<App />
</Theme>
</NetworkConnection>
</React.StrictMode>
);
}
22 changes: 22 additions & 0 deletions client/src/integrations/firebase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";

const firebaseConfig = {
apiKey: "AIzaSyDtWMlNHWufXi2weR1hYQTN9UjDqBOcV_4",
authDomain: "chat-app-6a541.firebaseapp.com",
databaseURL: "https://chat-app-6a541.firebaseio.com",
projectId: "chat-app-6a541",
storageBucket: "chat-app-6a541.appspot.com",
messagingSenderId: "856152974268",
appId: "1:856152974268:web:1f6e58076f79fc0a3f41b9",
measurementId: "G-V7CZLQ2CRK",
};

console.log(firebaseConfig);

const app = initializeApp(firebaseConfig);

export default class Firebase {
public static app = app;
public static auth = getAuth();
}
8 changes: 8 additions & 0 deletions client/src/integrations/network.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { FC, PropsWithChildren } from "react";

export const queryClient = new QueryClient();

export const NetworkConnection: FC<PropsWithChildren> = ({ children }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);
21 changes: 21 additions & 0 deletions client/src/store/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { GoogleAuthProvider, signInWithPopup } from "firebase/auth";
import { create } from "zustand";
import Firebase from "../integrations/firebase";

interface State {
refreshToken: string;
}

interface Action {
googleLogin: () => Promise<void>;
}

const useRootState = create<State & Action>((set) => ({
refreshToken: "",
googleLogin: async () => {
const res = await signInWithPopup(Firebase.auth, new GoogleAuthProvider());
set(() => ({ refreshToken: res.user.refreshToken }));
},
}));

export const useAuth = () => useRootState((state) => state);
16 changes: 16 additions & 0 deletions client/src/store/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { create } from "zustand";

interface State {
refreshToken: string;
}

interface Action {
setAuthData: () => void;
}

const useRootState = create<State & Action>((set) => ({
refreshToken: "",
setAuthData: () => {},
}));

export const useAuth = () => useRootState((state) => state);
Loading

0 comments on commit f1a72ea

Please sign in to comment.