这是indexloc提供的服务,不要输入任何密码
Skip to content

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 35 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
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 May 25, 2024
5b624ad
add env and add some comments
muzanella11 May 25, 2024
83e8d53
remove console
muzanella11 May 25, 2024
4897532
feat: Add Error component for displaying error messages
detautama May 22, 2024
e16b7f1
add blank layout
muzanella11 May 25, 2024
d51a6a5
add landing page
muzanella11 May 25, 2024
fd32a5e
add site data layout
muzanella11 May 25, 2024
b19f822
add signin and signup page
muzanella11 May 25, 2024
2a2c26c
add firebasui dependency
muzanella11 May 25, 2024
3384247
implement firebaseui in signin page
muzanella11 May 25, 2024
01b2223
add props isSignup in firebaseui component
muzanella11 May 25, 2024
d7e70b4
remove unused
muzanella11 May 25, 2024
eaa030a
put back changes
muzanella11 May 25, 2024
2624934
Merge branch 'next' into issue/340-authentication-user
muzanella11 May 25, 2024
a156209
add client only component
muzanella11 May 25, 2024
75c3eaa
add AuthUserContext
muzanella11 May 25, 2024
82e1bd9
add useFirebaseUi
muzanella11 May 25, 2024
e9cb8f4
add signout page for testing only
muzanella11 May 26, 2024
3ea0dfe
fix lint
muzanella11 May 26, 2024
582d564
put back apikey for temporary
muzanella11 May 26, 2024
2a23e31
add guest middleware
muzanella11 May 26, 2024
6b9c68f
add authenticated middleware
muzanella11 May 26, 2024
c0c9f95
add authaction for session handler
muzanella11 May 26, 2024
828f29f
dont save sensitive data user in session
muzanella11 May 26, 2024
feebdc3
save token to session after signin
muzanella11 May 26, 2024
94f334b
not need redirect after create session because firebaseui is already …
muzanella11 May 26, 2024
508d569
fix middleware too many redirect error
muzanella11 May 26, 2024
3a0d664
fix logic middleware
muzanella11 May 26, 2024
5b44699
remove signout route from middleware
muzanella11 May 26, 2024
94b9418
fix too many redirect error
muzanella11 May 26, 2024
5f54be9
set accessToken after signin
muzanella11 May 26, 2024
c9f32a4
finishing all
muzanella11 May 26, 2024
693c790
fix lint
muzanella11 May 26, 2024
3cbb881
remove pink background in authentication page
muzanella11 May 27, 2024
efd83ba
remove unused import styling
muzanella11 May 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions hosting/.env.development
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
7 changes: 7 additions & 0 deletions hosting/.env.production
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
2 changes: 1 addition & 1 deletion hosting/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ module.exports = {
quotes: "off", // Use config quotes from prettier, so we turn off this rules to avoiding conflict between eslint and prettier
},

ignorePatterns: ["**/src/js/*"],
ignorePatterns: ["**/src/assets/js/*"],
};
6 changes: 5 additions & 1 deletion hosting/next.config.mjs
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;
78 changes: 64 additions & 14 deletions hosting/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions hosting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"apexcharts": "^3.45.2",
"dotenv": "^16.4.5",
"firebase": "^10.12.0",
"firebaseui": "^6.1.0",
"flatpickr": "^4.6.13",
"jsvectormap": "^1.5.3",
"next": "^14.2.3",
Expand All @@ -39,6 +40,7 @@
"postcss": "^8",
"prettier": "^3.2.5",
"prettier-plugin-tailwindcss": "^0.5.11",
"sass": "^1.77.2",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
Expand Down
20 changes: 20 additions & 0 deletions hosting/src/actions/authAction.ts
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) {
Copy link
Member

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 🙏

Copy link
Contributor Author

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

Copy link
Contributor

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

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

Copy link
Member

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.

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);
}
8 changes: 3 additions & 5 deletions hosting/src/app/[site]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ export const metadata: Metadata = {

export default function Home() {
return (
<>
<DefaultLayout>
<ECommerce />
</DefaultLayout>
</>
<DefaultLayout>
<ECommerce />
</DefaultLayout>
);
}
32 changes: 32 additions & 0 deletions hosting/src/app/auth/signin/page.tsx
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>
);
}
36 changes: 36 additions & 0 deletions hosting/src/app/auth/signout/page.tsx
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>
</>
);
}
Loading