-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#340 add authentication pages using firebase UI #346
Conversation
hosting/libs/firebase/auth.ts
Outdated
} | ||
return result.user.uid; | ||
} catch (error) { | ||
console.error("Error signing in with Google", error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if we could display information to the user with a popup message when an error occurs and display an error message in the browser console just for developer debugging.
So the user can find out whether the process was a success or an error
console.error("Error signing in with Google", error); | |
Snackbar.error(new Error('Login failed')) | |
console.error(error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whenever possible, make an error service that wrap the error UI behavior and console log, so that we only call one method and can do customization in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in this commit
hosting/libs/firebase/auth.ts
Outdated
try { | ||
await firebaseAuth.signOut(); | ||
} catch (error) { | ||
console.error("Error signing out with Google", error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if we could handle this error condition and show some message to user with snackbar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would be helpful. Just avoid putting the details of the message from the error
in snackbar. The current console.error is good as it is. But it would indeed be helpful to get a snackbar informing that something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in this commit
hosting/libs/firebase/config.ts
Outdated
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID, | ||
}; | ||
|
||
const firebaseApp = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can optimizing this line code
const firebaseApp = | |
const firebaseApp = initializeApp(firebaseConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the way it's implemented in the docs of Firebase Frameworks Hosting
// get the authenticated Firebase App
const firebaseApp = getApp(useRouter().query.__firebaseAppName);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DennisAlund I got this error with your solution
Argument of type 'string | string[] | undefined' is not assignable to parameter of type 'string | undefined'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will go with @muzanella11 solution. Updated on this commit
import { createSession } from "../../../../../actions/auth-action"; | ||
import { signInWithGoogle } from "../../../../../libs/firebase/auth"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long and messy import. It would be better to use path alias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in this commit
import { SignOutWithGoogle } from "./components/SignOutWithGoogle"; | ||
import { firebaseAuth } from "../../../../libs/firebase/config"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long and messy import. It would be better to use path alias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in this commit
import { removeSession } from "../../../../../actions/auth-action"; | ||
import { signOutWithGoogle } from "../../../../../libs/firebase/auth"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long and messy import. It would be better to use path alias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in this commit
import DarkModeSwitcher from "./DarkModeSwitcher"; | ||
import DropdownMessage from "./DropdownMessage"; | ||
import DropdownNotification from "./DropdownNotification"; | ||
import DropdownUser from "./DropdownUser"; | ||
import DropdownUser from "./DropdownUser/DropdownUser"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to use path alias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in this commit
import React, { useEffect, useState } from "react"; | ||
import Sidebar from "@/components/Sidebar"; | ||
import Header from "@/components/Header"; | ||
import Loader from "../common/Loader"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long and messy import. It would be better to use path alias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in this commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation doesn't look like what I expected from using FirebaseUI: https://firebase.google.com/docs/auth/web/firebaseui
Is there a reason for doing manual buttons and handling?
hosting/libs/firebase/config.ts
Outdated
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID, | ||
}; | ||
|
||
const firebaseApp = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the way it's implemented in the docs of Firebase Frameworks Hosting
// get the authenticated Firebase App
const firebaseApp = getApp(useRouter().query.__firebaseAppName);
const [loading, setLoading] = useState<boolean>(true); | ||
|
||
useEffect(() => { | ||
setTimeout(() => setLoading(false), 2000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming this loading part is implemented as a placeholder to show usage for later when we are loading data from Firestore?
Please consider either of the following options
- Add a comment such as
// Fetch your data here and set loading to false when done
- Remove the loading things until we're loading data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I choose number 1
Updated in this commit
…s://github.com/oddbit/tanam into #340-Add-Authentication-Pages-using-FirebaseUI
We already have it all: A page to show sign in button and a button to sign in with google account, that's a reason. I didn't find any reason to use firebaseUI. Or are there something that I missed from FirebaseUI? |
…Authentication-Pages-using-FirebaseUI
# Conflicts: # hosting/src/app/auth/signin/page.tsx # hosting/src/app/auth/signup/page.tsx # hosting/src/app/layout.tsx # hosting/src/components/Header/DropdownUser/DropdownUser.tsx # hosting/src/components/Header/index.tsx # hosting/src/components/Layouts/DefaultLayout.tsx # hosting/src/components/Maps/MapOne.tsx # hosting/src/firebase.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hook files should be camelCase. Please rename this one to useUserSession.tsx
hosting/src/libs/firebase/auth.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this one won't be needed if we are using Firebase UI for auth? 🙏
import {removeSession} from "@/actions/auth-action"; | ||
import {signOutWithGoogle} from "@/libs/firebase/auth"; | ||
|
||
export const SignOutWithGoogle = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we rename the operation to just "sign out" since the sign out flow will be the same for all providers when we add more in the future.
hosting/src/actions/auth-action.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the auth action in terms of Next terminology? Can you help me with a pointer to the docs for me to learn what pattern this is 🙏
Visit the preview URL for this PR (updated for commit d4496a8): https://tanam-testing--pr346-340-add-authenticat-2uc7akdn.web.app (expires Fri, 31 May 2024 23:33:30 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 5bbe8a1a68d9684d656bffba10008fe532204561 |
Replaced by #354 |
Description
Implement authentication for the Tanam web application using firebaseui-web. The authentication should only support sign-in with Google. The site should be accessible only if the user is signed in, and upon successful sign-in, the user should be redirected to the landing page.
Requirements
🛑 FirebaseUI Implementation: I think we don't need this. We can create sign in ui by ourself
Access Control
✅ Ensure the site is accessible only to authenticated users.
✅ Redirect unauthenticated users to the sign-in page.
Post-Sign-In Redirection
✅ Redirect signed-in users to the landing page.
Referenced issues
Closes #340