Skip to content

Commit

Permalink
fix: use secure cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
olemathias committed Mar 17, 2023
1 parent d2d002c commit f9a70aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ KEYCLOAK_REALM=wannabe5-dev
NEXTAUTH_SECRET=lol123456789
NEXTAUTH_URL=http://localhost:3000

BASE_URL=http://localhost:3000
URL=http://localhost:3000
API_URL=http://127.0.0.1:8000/api
7 changes: 6 additions & 1 deletion src/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ App.propTypes = {
};

App.getInitialProps = async (appContext) => {
const cookieName =
process.env.NODE_ENV === "production"
? "__Secure-next-auth.session-token"
: "next-auth.session-token";

// Server Side
if (appContext.ctx.req) {
try {
const response = await axios({
method: "GET",
url: `${publicRuntimeConfig.url}/api/auth/user`,
headers: {
Cookie: `next-auth.session-token=${appContext.ctx.req.cookies["next-auth.session-token"]}`,
Cookie: `${cookieName}=${appContext.ctx.req.cookies[cookieName]}`,
},
});
return { user: response?.data?.user };
Expand Down

0 comments on commit f9a70aa

Please sign in to comment.