Skip to content

Commit

Permalink
[DPCP-62] Alpha: Consolidate in www. (#28)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
angeloreale authored Aug 6, 2024
1 parent b2ab189 commit aa01298
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 10 deletions.
2 changes: 0 additions & 2 deletions .env.public
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 10 additions & 4 deletions lib/auth/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -25,21 +25,27 @@ 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);
}
},
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',
Expand Down
7 changes: 6 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand All @@ -23,6 +23,11 @@ const nextConfig = {
destination: '/services/rickmorty/list',
permanent: false,
},
// {
// source: '/signin',
// destination: '/dash/signin',
// permanent: false,
// },
];
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/client/elements/signin-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ export const VSignIn = ({ user }: VSignInProps) => {
</div>
);

return <DPButton onClick={() => navigate('/api/auth/signin')}>Sign in</DPButton>;
return <DPButton onClick={() => navigate('/api/v1/auth/signin')}>Sign in</DPButton>;
};
4 changes: 2 additions & 2 deletions src/app/components/client/elements/signup-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || "/"

Expand All @@ -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(() => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,24 @@ export const config = {
matcher: ['/api/:path*'],
};

const headers: Record<string, any> = {
// '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,
Expand Down

0 comments on commit aa01298

Please sign in to comment.