Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Fix/create wish #99

Merged
merged 6 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions src/pages/api/auth/[...nextauth]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import Providers from "next-auth/providers";
import process from "process";

const prisma = new PrismaClient();
const useSecureCookies = process.env.NEXTAUTH_URL.startsWith("https://");
const cookiePrefix = useSecureCookies ? "__Secure-" : "";
const hostName = new URL(process.env.NEXTAUTH_URL).hostname;
const domain = hostName === "localhost" ? hostName : "." + hostName;

/* eslint-disable new-cap */
export default NextAuth({
Expand All @@ -34,6 +38,31 @@ export default NextAuth({
adapter: Adapters.Prisma.Adapter({ prisma }),
secret: process.env.SECRET,

cookies: {
// Allow cookies on sub-domains (like api.dekk.app) by adding
// a . infront of the hostname (like .dekk.app)
sessionToken: {
name: `${cookiePrefix}next-auth.session-token`,
options: {
httpOnly: true,
sameSite: "lax",
path: "/",
secure: useSecureCookies,
domain,
},
},
csrfToken: {
name: `${cookiePrefix}next-auth.csrf-token`,
options: {
httpOnly: true,
sameSite: "lax",
path: "/",
secure: useSecureCookies,
domain,
},
},
},

// @TODO: Use https://github.com/praveenweb/next-auth-hasura-example/blob/main/pages/api/auth/%5B...nextauth%5D.js
// to make sure the JWT is send in the session

Expand Down
2 changes: 1 addition & 1 deletion src/pages/auth/error/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async context =
session,
locale: context.locale,
consent: getServerSideCookieConsent(context),
cookie: context.req.headers.cookie,
cookie: context.req.headers.cookie || null,
},
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/auth/signin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async context =
session,
locale: context.locale,
consent: getServerSideCookieConsent(context),
cookie: context.req.headers.cookie,
cookie: context.req.headers.cookie || null,
},
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/auth/signout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async context =
session,
locale: context.locale,
consent: getServerSideCookieConsent(context),
cookie: context.req.headers.cookie,
cookie: context.req.headers.cookie || null,
},
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/auth/verify-request/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async context =
session: await getSession(context),
locale: context.locale,
consent: getServerSideCookieConsent(context),
cookie: context.req.headers.cookie,
cookie: context.req.headers.cookie || null,
},
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async context =
session: await getSession(context),
locale: context.locale,
consent: getServerSideCookieConsent(context),
cookie: context.req.headers.cookie,
cookie: context.req.headers.cookie || null,
},
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/legal/cookie-policy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async context =
providers: await getProviders(),
locale: context.locale,
consent: getServerSideCookieConsent(context),
cookie: context.req.headers.cookie,
cookie: context.req.headers.cookie || null,
},
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/wishlist/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async context =
providers: await getProviders(),
locale: context.locale,
consent: getServerSideCookieConsent(context),
cookie: context.req.headers.cookie,
cookie: context.req.headers.cookie || null,
},
});
};
Expand Down