Skip to content

Commit

Permalink
Fix secure restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
pozylon committed Oct 25, 2024
1 parent c2bbde0 commit d22c494
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions examples/kitchensink/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const { UNCHAINED_COOKIE_NAME = 'unchained_token' } = process.env;
const start = async () => {
const app = express();

// Workaround Express Secure Proxy
app.set('trust proxy', 1);
app.use((req, res, next) => {
req.headers['x-forwarded-proto'] = 'https';
res.setHeader('Access-Control-Allow-Private-Network', 'true');
next();
});
Expand Down
7 changes: 3 additions & 4 deletions packages/api/src/express/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const {
UNCHAINED_COOKIE_NAME = 'unchained_token',
UNCHAINED_COOKIE_PATH = '/',
UNCHAINED_COOKIE_DOMAIN,
NODE_ENV,
} = process.env;

const addContext = async function middlewareWithContext(
Expand Down Expand Up @@ -133,10 +132,10 @@ export const connect = (
resave: false,
cookie: {
domain: UNCHAINED_COOKIE_DOMAIN,
httpOnly: true,
path: UNCHAINED_COOKIE_PATH,
sameSite: 'lax',
secure: NODE_ENV === 'production',
sameSite: 'none',
secure: true,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 7,
},
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from '@unchainedshop/logger';
import { InvalidCredentialsError } from '../../../errors.js';
import { InvalidCredentialsError, UserNotFoundError } from '../../../errors.js';
import { Context } from '../../../types.js';

export default async function loginWithPassword(
Expand All @@ -22,6 +22,8 @@ export default async function loginWithPassword(
? await context.modules.users.findUserByUsername(username)
: await context.modules.users.findUserByEmail(email);

if (!user) throw new InvalidCredentialsError({ username, email });

const verified =
user.services?.password &&
(await context.modules.users.verifyPassword(user.services.password, password));
Expand Down

0 comments on commit d22c494

Please sign in to comment.