-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added firebase auth integration
- Loading branch information
1 parent
85b28bc
commit f1a72ea
Showing
16 changed files
with
543 additions
and
535 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Binary file not shown.
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,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); | ||
}, | ||
}); | ||
}; |
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,8 @@ | ||
export const { | ||
FIREBASE_API_KEY, | ||
FIREBASE_APP_ID, | ||
FIREBASE_AUTH_DOMAIN, | ||
FIREBASE_MEASUREMENT_ID, | ||
FIREBASE_MESSAGE_SENDER_ID, | ||
FIREBASE_PROJECT_ID, | ||
} = process.env; |
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 |
---|---|---|
@@ -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; | ||
} |
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 |
---|---|---|
@@ -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> | ||
); | ||
} |
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,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(); | ||
} |
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,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> | ||
); |
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,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); |
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,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); |
Oops, something went wrong.