From aa01298b259a37cb65878709dc9231110db0421b Mon Sep 17 00:00:00 2001
From: Angelo Reale <12191809+angeloreale@users.noreply.github.com>
Date: Wed, 7 Aug 2024 00:55:44 +0100
Subject: [PATCH] [DPCP-62] Alpha: Consolidate in www. (#28)
* ar(fix) [DPCP-XX]: Consolidate Domain
* ar(fix) [DPCP-XX]: Consolidate Domain
* ar(fix) [DPCP-XX]: update packages
* ar(fix) [DPCP-XX]: update packages
* ar(fix) [DPCP-XX]: update packages
---
.env.public | 2 --
lib/auth/constants.ts | 14 ++++++++++----
next.config.js | 7 ++++++-
src/app/components/client/elements/signin-view.tsx | 2 +-
src/app/components/client/elements/signup-view.tsx | 4 ++--
src/app/{ => dash}/error/page.tsx | 0
src/app/{ => dash}/services/hypnos/[mode]/page.tsx | 0
.../{ => dash}/services/rickmorty/[mode]/page.tsx | 0
src/app/{ => dash}/signin/page.tsx | 0
src/app/{ => dash}/verify/page.tsx | 0
src/middleware.ts | 14 ++++++++++++++
11 files changed, 33 insertions(+), 10 deletions(-)
rename src/app/{ => dash}/error/page.tsx (100%)
rename src/app/{ => dash}/services/hypnos/[mode]/page.tsx (100%)
rename src/app/{ => dash}/services/rickmorty/[mode]/page.tsx (100%)
rename src/app/{ => dash}/signin/page.tsx (100%)
rename src/app/{ => dash}/verify/page.tsx (100%)
diff --git a/.env.public b/.env.public
index b617290b..35595232 100644
--- a/.env.public
+++ b/.env.public
@@ -8,8 +8,6 @@
# @@@ WARNING: DON'T ADD NEXT_PUBLIC_* VARIABLES IF THEY'RE PRIVATE @@@
# env specific
-NEXTAUTH_SECRET=random-string
-NEXTAUTH_URL=http://localhost:3000
API_HOST_DEV=
API_HOST=http://localhost:3001
diff --git a/lib/auth/constants.ts b/lib/auth/constants.ts
index f397c836..2e0f49ee 100644
--- a/lib/auth/constants.ts
+++ b/lib/auth/constants.ts
@@ -11,7 +11,7 @@ const methods = {
signIn: () => {},
signOut: async () => {
try {
- const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/auth/signout`, {
+ const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/v1/auth/signout`, {
method: 'POST',
headers: {
Accept: 'application/json',
@@ -25,9 +25,16 @@ const methods = {
}
},
getCsrf: async () => {
+ console.log('GETTING CSTF');
try {
- const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/auth/csrf`, { credentials: 'include' });
+ const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/v1/auth/csrf`, {
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ },
+ });
const csrf = await response.json();
+ console.log({ response, csrf });
return csrf.csrfToken;
} catch (e) {
console.error(e);
@@ -35,11 +42,10 @@ const methods = {
},
getSession: async (params = { cookies: '' }) => {
try {
- const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/auth/session`, {
+ const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/v1/auth/session`, {
method: 'GET',
headers: {
Accept: 'application/json',
- 'Content-Type': 'application/json',
Cookie: params?.cookies,
},
credentials: 'include',
diff --git a/next.config.js b/next.config.js
index aa4efa83..49e3d45c 100644
--- a/next.config.js
+++ b/next.config.js
@@ -1,7 +1,7 @@
/** @type {import('next').NextConfig} */
const { withSentryConfig } = require('@sentry/nextjs');
const nextConfig = {
- basePath: process.env.NEXUS_BASE_PATH,
+ assetPrefix: process.env.NEXT_PUBLIC_NEXUS_HOST || 'https://nyx.dreampip.com',
transpilePackages: ['next-auth'],
images: {
remotePatterns: [
@@ -23,6 +23,11 @@ const nextConfig = {
destination: '/services/rickmorty/list',
permanent: false,
},
+ // {
+ // source: '/signin',
+ // destination: '/dash/signin',
+ // permanent: false,
+ // },
];
},
};
diff --git a/src/app/components/client/elements/signin-view.tsx b/src/app/components/client/elements/signin-view.tsx
index 3b04addf..f776c5eb 100644
--- a/src/app/components/client/elements/signin-view.tsx
+++ b/src/app/components/client/elements/signin-view.tsx
@@ -45,5 +45,5 @@ export const VSignIn = ({ user }: VSignInProps) => {
);
- return navigate('/api/auth/signin')}>Sign in;
+ return navigate('/api/v1/auth/signin')}>Sign in;
};
diff --git a/src/app/components/client/elements/signup-view.tsx b/src/app/components/client/elements/signup-view.tsx
index 3e997c81..970fed7c 100644
--- a/src/app/components/client/elements/signup-view.tsx
+++ b/src/app/components/client/elements/signup-view.tsx
@@ -45,7 +45,7 @@ export const VSignUp = ({ providers, user }: VSignUpProps) => {
const oauth = _providers.slice(1, providers.length)
const defaultP = _providers[0]
- const signInUrl = '/api/auth/signin'
+ const signInUrl = '/api/v1/auth/signin'
const callbackUrl = process.env.NEXT_PUBLIC_NEXUS_BASE_PATH || "/"
@@ -54,7 +54,7 @@ export const VSignUp = ({ providers, user }: VSignUpProps) => {
const coercedName = name || user?.name || user?.email || "Young Padawan";
useEffect(() => {
- getCsrf().then((_csrf) => setCsrf(_csrf));
+ if(!csrf) getCsrf().then((_csrf) => setCsrf(_csrf));
}, [csrf]);
useEffect(() => {
diff --git a/src/app/error/page.tsx b/src/app/dash/error/page.tsx
similarity index 100%
rename from src/app/error/page.tsx
rename to src/app/dash/error/page.tsx
diff --git a/src/app/services/hypnos/[mode]/page.tsx b/src/app/dash/services/hypnos/[mode]/page.tsx
similarity index 100%
rename from src/app/services/hypnos/[mode]/page.tsx
rename to src/app/dash/services/hypnos/[mode]/page.tsx
diff --git a/src/app/services/rickmorty/[mode]/page.tsx b/src/app/dash/services/rickmorty/[mode]/page.tsx
similarity index 100%
rename from src/app/services/rickmorty/[mode]/page.tsx
rename to src/app/dash/services/rickmorty/[mode]/page.tsx
diff --git a/src/app/signin/page.tsx b/src/app/dash/signin/page.tsx
similarity index 100%
rename from src/app/signin/page.tsx
rename to src/app/dash/signin/page.tsx
diff --git a/src/app/verify/page.tsx b/src/app/dash/verify/page.tsx
similarity index 100%
rename from src/app/verify/page.tsx
rename to src/app/dash/verify/page.tsx
diff --git a/src/middleware.ts b/src/middleware.ts
index 285d043b..4f06f256 100644
--- a/src/middleware.ts
+++ b/src/middleware.ts
@@ -6,10 +6,24 @@ export const config = {
matcher: ['/api/:path*'],
};
+const headers: Record = {
+ // 'Access-Control-Allow-Origin': process.env.MAIN_URL || 'https://alpha.dreampip.com',
+ 'Cache-Control': 'maxage=0, s-maxage=300, stale-while-revalidate=300',
+ // DEV-DEBUG:
+ // 'content-type': 'application/json',
+ 'Access-Control-Allow-Origin': 'https://beta.dreampip.com',
+ 'Access-Control-Allow-Credentials': 'true',
+ 'Access-Control-Allow-Headers': '*',
+};
+
export function middleware(request: NextRequest) {
const response = NextResponse.next();
const pkce = request.cookies.get('next-auth.pkce.code_verifier');
+ Object.keys(headers).forEach((key: string) => {
+ response.headers.set(key, headers[key]);
+ });
+
if (pkce?.value) {
response.cookies.set('next-auth.pkce.code_verifier', pkce.value, {
httpOnly: true,