#middleware bcrypt

24 messages · Page 1 of 1 (latest)

flat grove
#
 ⨯ ./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <!doctype html>
| <html>
| <head>

Import trace for requested module:
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js
./src/lib/auth/provider.ts
./src/lib/auth/utils.ts
 ⚠ ./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js
Module not found: Can't resolve 'npm' in 'D:\panel\node_modules\.pnpm\@mapbox+node-pre-gyp@1.0.11\node_modules\@mapbox\node-pre-gyp\lib\util'
solid viperBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

vestal arrow
#

middleware run on edge runtime which does not support bcrypt

flat grove
#

ok now I'm using bcryptjs now this comes:

 node_modules\.pnpm\redis-errors@1.2.0\node_modules\redis-errors\index.js (3:0) @ <unknown>
 ⨯ Cannot read properties of undefined (reading 'charCodeAt')
nullCompiling /not-found ...
 ✓ Compiled /not-found in 775ms (395 modules)
 ⚠ Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/messages/fast-refresh-reload
 ⨯ node_modules\.pnpm\redis-errors@1.2.0\node_modules\redis-errors\index.js (3:0) @ <unknown>
 ⨯ Cannot read properties of undefined (reading 'charCodeAt')
null
 ⨯ node_modules\.pnpm\redis-errors@1.2.0\node_modules\redis-errors\index.js (3:0) @ <unknown>
 ⨯ Cannot read properties of undefined (reading 'charCodeAt')
null
vestal arrow
#

are you using redis for nodejs?

flat grove
#

yes I'm using ioredis

vestal arrow
#

which require node api

#

are you using next-auth and want to handle authorization in middelware

flat grove
#

no

vestal arrow
#

ok

flat grove
#

I want to handle auth in middleware but using a custom system

#

export const validateSession = async (): Promise<User | null> => {
  const cookie = cookies().get("SESSION");
  if (cookie === undefined) {
    return null;
  }
  const sessionId = cookie.value;

  if (!validator.isUUID(sessionId)) {
    return null;
  }

  const redis = createRedisInstance();

  const session = await redis.get(`session:${sessionId}`);

  if (session === null) {
    return null;
  }

  let userId = Number(session);
  if (isNaN(userId)) {
    return null;
  }

  const userInfo = await AUTH.info(userId);

  if (userInfo === null) {
    return null;
  }

  return {
    id: userId,
    email: userInfo.email,
    username: userInfo.username,
    first_name: userInfo.first_name,
    last_name: userInfo.last_name,
  };
};

middleware:

export async function middleware(request: NextRequest) {
  if (request.nextUrl.pathname.startsWith("/sign-in")) return;
  const user = validateSession();
  if (user === null)
    NextResponse.redirect("/sign-in", {
      status: 302,
    });
}

vestal arrow
#

can you turn validateSession to a route handler and try to fetch it in middleware?

#

or use upstash redis

flat grove
vestal arrow
#

redirect from middleware?

flat grove
#

yeah

vestal arrow
#

does refresh show the style?

flat grove
#

ok nvm the styles are completely gone

vestal arrow
#

yeah I think your middleware is blocking the css request

#

add the matcher in config

flat grove
#

yeah works

#

thx