Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
haiphucnguyen committed Dec 27, 2024
1 parent b52049c commit afc7b71
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 143 deletions.
1 change: 0 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ jobs:
- run: pnpm install
- name: Build the application
env:
NEXT_PUBLIC_API_URL: "http://localhost:8080"
BACK_END_URL: "http://localhost:8080"
run: pnpm build
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ Set up the application environment variables by running the following script:
scripts/init_environments.sh
```

This script generates environment variables, including NEXT_PUBLIC_API_URL, to establish the communication between the client and server. Example
This script generates environment variables, including BACK_END_URL, to establish the communication between the client and server. Example

```
NEXT_PUBLIC_API_URL=http://localhost:8080
BACK_END_URL=http://localhost:8080
```

We recommend running the `scripts/all.sh` script, as it streamlines the process by checking your environment settings and performing all necessary configurations, removing the need to execute multiple scripts manually.
Expand Down
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const nextConfig = {
fallback: [
{
source: "/api/:path*",
destination: `${process.env.NEXT_PUBLIC_API_URL}/api/:path*`,
destination: `${process.env.BACK_END_URL}/api/:path*`,
},
],
};
Expand Down
22 changes: 11 additions & 11 deletions scripts/docker_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ docker tag ${IMAGE_NAME} ${REMOTE_REPO}:${TAG}
docker tag ${IMAGE_NAME} ${REMOTE_REPO}:latest

# Step 3: Log in to the Docker repository (Docker Hub by default)
#echo "Logging into Docker repository..."
#docker login || { echo "Login failed"; exit 1; }
#
## Step 4: Push both tags to the remote repository
#echo "Pushing Docker image to remote repository with tag '${TAG}'..."
#docker push ${REMOTE_REPO}:${TAG}
#
#echo "Pushing Docker image to remote repository with tag 'latest'..."
#docker push ${REMOTE_REPO}:latest
#
#echo "Docker image has been pushed successfully with tags '${TAG}' and 'latest'."
echo "Logging into Docker repository..."
docker login || { echo "Login failed"; exit 1; }

# Step 4: Push both tags to the remote repository
echo "Pushing Docker image to remote repository with tag '${TAG}'..."
docker push ${REMOTE_REPO}:${TAG}

echo "Pushing Docker image to remote repository with tag 'latest'..."
docker push ${REMOTE_REPO}:latest

echo "Docker image has been pushed successfully with tags '${TAG}' and 'latest'."
3 changes: 1 addition & 2 deletions scripts/init_environments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ while true; do
done

# Append to the .env.local file
echo "NEXT_PUBLIC_API_URL=\"$backend_server\"" >> "$output_file"
echo "BACK_END_URL=\"$backend_server\"" >> "$output_file"
echo "NEXT_PUBLIC_BACK_END_URL=\"$backend_server\"" >> "$output_file"


# Run npx auth and append its output to .env
Expand Down
14 changes: 14 additions & 0 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import NextAuth, { User } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

import apiAuthSignIn from "@/lib/auth";
import { BASE_URL } from "@/lib/constants";

export const { handlers, auth } = NextAuth({
providers: [
Expand All @@ -23,6 +24,19 @@ export const { handlers, auth } = NextAuth({
}),
],
callbacks: {
async redirect({ url, baseUrl }) {
// Allows relative callback URLs
if (url.startsWith("/")) return `${baseUrl}${url}`;
// Works for the deployment model while API_URL is the front url of the reverse proxy
else if (
process.env.NODE_ENV === "production" &&
new URL(url).origin === BASE_URL
)
return url;
// Allows callback URLs on the same origin
else if (new URL(url).origin === baseUrl) return url;
return baseUrl;
},
jwt({ token, account, user }) {
if (user) {
token.accessToken = user?.accessToken;
Expand Down
26 changes: 22 additions & 4 deletions src/components/admin-panel/user-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { API_URL } from "@/lib/constants";
import { BASE_URL } from "@/lib/constants";

export function UserNav() {
const { data: session } = useSession();
Expand All @@ -50,7 +50,7 @@ export function UserNav() {
<AvatarImage
src={
session?.user?.imageUrl
? `${API_URL}/api/files/${session?.user?.imageUrl}`
? `${BASE_URL}/api/files/${session?.user?.imageUrl}`
: undefined
}
alt="Avatar"
Expand Down Expand Up @@ -102,7 +102,7 @@ export function UserNav() {
<DropdownMenuSeparator />
<DropdownMenuItem
className="hover:cursor-pointer"
onClick={() => signOut()}
onClick={() => signOut({ redirectTo: BASE_URL, redirect: true })}
>
<LogOut className="w-4 h-4 mr-3 text-muted-foreground" />
Sign out
Expand All @@ -112,7 +112,7 @@ export function UserNav() {
<DialogContent>
<DialogHeader className="flex items-center space-x-4">
<div>
<AppLogo />
<AppLogo size={100} />
</div>

<div>
Expand All @@ -127,6 +127,24 @@ export function UserNav() {
</DialogDescription>
</div>
</DialogHeader>

{/* Footer */}
<div className="mt-2 flex justify-between items-center border-t pt-2">
{/* Copyright and Year */}
<div className="text-sm text-gray-500 dark:text-gray-400">
© {new Date().getFullYear()} FlowInquiry. All rights reserved.
</div>

{/* Website Link */}
<a
href="https://www.flowinquiry.io"
target="_blank"
rel="noopener noreferrer"
className="text-sm font-medium text-blue-600 hover:underline dark:text-blue-400"
>
flowinquiry.io
</a>
</div>
</DialogContent>
</Dialog>
);
Expand Down
61 changes: 31 additions & 30 deletions src/components/app-logo.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
import React from "react";

type IconProps = React.HTMLAttributes<SVGElement>;
type IconProps = React.HTMLAttributes<SVGElement> & {
size?: number;
};

const AppLogo = (props: IconProps) => {
const AppLogo = ({ size = 40, ...props }: IconProps) => {
return (
<>
<svg
width="40"
height="40"
viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"
>
<path
transform="scale(1.00287,1.00287)"
d="M30 100c-16.569 0-30-13.431-30-30v-40c0-16.569 13.431-30 30-30h40c16.569 0 30 13.431 30 30v40c0 16.569-13.431 30-30 30z"
fill="#000000"
stroke="none"
strokeWidth="1"
/>
<path
d="M49.942 52.994L90.595 51.529C88.068 47.352 87.436 43.698 82.606 43.068 75.377 42.128 68.148 41.185 60.918 40.242L18.843 34.762C20.101 36.792 39.724 53.361 49.942 52.994"
fill="#ffffff"
/>
<path
d="M0 9.786C4.391 17.043 26.615 32.858 32.953 33.672 50.283 35.903 67.61 38.132 84.939 40.36 81.546 34.753 80.759 31.01 74.627 29.401L47.91 22.378C31.94 18.182 15.97 13.984 0 9.786"
fill="#ffffff"
/>
<path
d="M63.108 66.207L94.349 59.547C92.321 56.201 92.315 54.188 88.522 54.358 82.364 54.631 76.208 54.907 70.051 55.18 58.708 55.686 47.365 56.194 36.023 56.698 37.298 58.064 54.94 67.947 63.108 66.207"
fill="#ffffff"
/>
</svg>
</>
<svg
width={size}
height={size}
viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
transform="scale(1.00287,1.00287)"
d="M30 100c-16.569 0-30-13.431-30-30v-40c0-16.569 13.431-30 30-30h40c16.569 0 30 13.431 30 30v40c0 16.569-13.431 30-30-30z"
fill="#000000"
stroke="none"
strokeWidth="1"
/>
<path
d="M49.942 52.994L90.595 51.529C88.068 47.352 87.436 43.698 82.606 43.068 75.377 42.128 68.148 41.185 60.918 40.242L18.843 34.762C20.101 36.792 39.724 53.361 49.942 52.994"
fill="#ffffff"
/>
<path
d="M0 9.786C4.391 17.043 26.615 32.858 32.953 33.672 50.283 35.903 67.61 38.132 84.939 40.36 81.546 34.753 80.759 31.01 74.627 29.401L47.91 22.378C31.94 18.182 15.97 13.984 0 9.786"
fill="#ffffff"
/>
<path
d="M63.108 66.207L94.349 59.547C92.321 56.201 92.315 54.188 88.522 54.358 82.364 54.631 76.208 54.907 70.051 55.18 58.708 55.686 47.365 56.194 36.023 56.698 37.298 58.064 54.94 67.947 63.108 66.207"
fill="#ffffff"
/>
</svg>
);
};

Expand Down
Loading

0 comments on commit afc7b71

Please sign in to comment.