-
Notifications
You must be signed in to change notification settings - Fork 41
feat: authentication user #354
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
f8f6d3d
move firebase to plugins
muzanella11 5b624ad
add env and add some comments
muzanella11 83e8d53
remove console
muzanella11 4897532
feat: Add Error component for displaying error messages
detautama e16b7f1
add blank layout
muzanella11 d51a6a5
add landing page
muzanella11 fd32a5e
add site data layout
muzanella11 b19f822
add signin and signup page
muzanella11 2a2c26c
add firebasui dependency
muzanella11 3384247
implement firebaseui in signin page
muzanella11 01b2223
add props isSignup in firebaseui component
muzanella11 d7e70b4
remove unused
muzanella11 eaa030a
put back changes
muzanella11 2624934
Merge branch 'next' into issue/340-authentication-user
muzanella11 a156209
add client only component
muzanella11 75c3eaa
add AuthUserContext
muzanella11 82e1bd9
add useFirebaseUi
muzanella11 e9cb8f4
add signout page for testing only
muzanella11 3ea0dfe
fix lint
muzanella11 582d564
put back apikey for temporary
muzanella11 2a23e31
add guest middleware
muzanella11 6b9c68f
add authenticated middleware
muzanella11 c0c9f95
add authaction for session handler
muzanella11 828f29f
dont save sensitive data user in session
muzanella11 feebdc3
save token to session after signin
muzanella11 94f334b
not need redirect after create session because firebaseui is already …
muzanella11 508d569
fix middleware too many redirect error
muzanella11 3a0d664
fix logic middleware
muzanella11 5b44699
remove signout route from middleware
muzanella11 94b9418
fix too many redirect error
muzanella11 5f54be9
set accessToken after signin
muzanella11 c9f32a4
finishing all
muzanella11 693c790
fix lint
muzanella11 3cbb881
remove pink background in authentication page
muzanella11 efd83ba
remove unused import styling
muzanella11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,10 @@ | ||
# It will be better if we set this env value to server config when we deploy this project | ||
# To avoid get email notification `Suspicious Activity Alert` from google | ||
# "Publicly accessible Google API key for Google Cloud Platform project Tanam Development Project (id: tanam-testing)" | ||
NEXT_PUBLIC_FIREBASE_API_KEY=AIzaSyDGYwmKdPdUXkO6abAaLf6BHL8vqqvzdvQ | ||
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=tanam-testing.firebaseapp.com | ||
NEXT_PUBLIC_FIREBASE_DATABASE_URL=https://tanam-testing.firebaseio.com | ||
NEXT_PUBLIC_FIREBASE_PROJECT_ID=tanam-testing | ||
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=tanam-testing.appspot.com | ||
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=33159958289 | ||
NEXT_PUBLIC_FIREBASE_APP_ID=1:33159958289:web:1056a48a098332d8fd46b0 |
This file contains hidden or 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,7 @@ | ||
NEXT_PUBLIC_FIREBASE_API_KEY=AIzaSyDGYwmKdPdUXkO6abAaLf6BHL8vqqvzdvQ | ||
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=tanam-testing.firebaseapp.com | ||
NEXT_PUBLIC_FIREBASE_DATABASE_URL=https://tanam-testing.firebaseio.com | ||
NEXT_PUBLIC_FIREBASE_PROJECT_ID=tanam-testing | ||
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=tanam-testing.appspot.com | ||
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=33159958289 | ||
NEXT_PUBLIC_FIREBASE_APP_ID=1:33159958289:web:1056a48a098332d8fd46b0 |
This file contains hidden or 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 hidden or 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,4 +1,8 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
const nextConfig = { | ||
images: { | ||
domains: ["lh3.googleusercontent.com"], | ||
}, | ||
}; | ||
|
||
export default nextConfig; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,20 @@ | ||
"use server"; | ||
|
||
import {cookies} from "next/headers"; | ||
import {redirect} from "next/navigation"; | ||
import {SIGN_IN_ROUTE, SESSION_COOKIE_NAME} from "@/constants"; | ||
|
||
export async function createSession(token: string) { | ||
cookies().set(SESSION_COOKIE_NAME, token, { | ||
httpOnly: true, | ||
secure: process.env.NODE_ENV === "production", | ||
maxAge: 60 * 60 * 24, // One day | ||
path: "/", | ||
}); | ||
} | ||
|
||
export async function removeSession() { | ||
cookies().delete(SESSION_COOKIE_NAME); | ||
|
||
redirect(SIGN_IN_ROUTE); | ||
} |
This file contains hidden or 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 hidden or 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,32 @@ | ||
import "@/assets/scss/layout-authentication.scss"; | ||
import {Metadata} from "next"; | ||
import Image from "next/image"; | ||
import BlankLayout from "@/components/Layouts/BlankLayout"; | ||
import FirebaseUi from "@/components/FirebaseUi"; | ||
import ClientOnly from "@/components/ClientOnly"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Tanam | Signin", | ||
description: "Signin in Tanam", | ||
}; | ||
|
||
export default function SigninPage() { | ||
return ( | ||
<BlankLayout> | ||
<section className="l-authentication"> | ||
<div className="fixed left-1/2 top-1/2 w-1/3 -translate-x-1/2 -translate-y-1/2 transform text-center"> | ||
<div className="flex justify-center"> | ||
<Image src="/favicon.ico" width={80} height={80} alt="tanam icon" /> | ||
<h1 className="text-gray-500 mt-10 text-lg font-bold authentication__title">Signin</h1> | ||
</div> | ||
|
||
<div className="authentication__wrapper-content"> | ||
<ClientOnly> | ||
<FirebaseUi isSignUp={false} /> | ||
</ClientOnly> | ||
</div> | ||
</div> | ||
</section> | ||
</BlankLayout> | ||
); | ||
} |
This file contains hidden or 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,36 @@ | ||
import React from "react"; | ||
import "@/assets/scss/layout-authentication.scss"; | ||
import {Metadata} from "next"; | ||
import Image from "next/image"; | ||
import BlankLayout from "@/components/Layouts/BlankLayout"; | ||
// import AuthUser from "@/components/AuthUser"; | ||
import SignoutUser from "@/components/SignoutUser"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Tanam | Signout", | ||
description: "Signout in Tanam", | ||
}; | ||
|
||
export default function SignoutPage() { | ||
return ( | ||
<> | ||
<BlankLayout> | ||
<section className="l-authentication"> | ||
<div className="fixed left-1/2 top-1/2 w-1/3 -translate-x-1/2 -translate-y-1/2 transform text-center"> | ||
<div className="flex justify-center"> | ||
<Image src="/favicon.ico" width={80} height={80} alt="tanam icon" /> | ||
</div> | ||
|
||
<SignoutUser /> | ||
|
||
{/* Showing this section when you want to check auth user data */} | ||
{/* <div className="authentication__wrapper-content"> | ||
Logout | ||
<AuthUser /> | ||
</div> */} | ||
</div> | ||
</section> | ||
</BlankLayout> | ||
</> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 you please link me to the React+Firebase documentation for this 🙏
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 haven't read all the documentation on nextjs, I just fixed a little of @detautama PR #346 regarding these changes. Maybe it's not perfect but I would love to read best practices from @detautama regarding these changes
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 is Session Management in Server Actions. This is the documentation about Server Actions
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.
Basically, server actions are used for operations on the server side (fetch data, authentication, etc), but in practice they can also be called in the client component
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.
Thank you @detaoddbit what happens if you remove that? I find it peculiar that next requires an additional session handling on top of Firebase Authentication.