Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackAssertionError (while trying to signin) #310

Open
suryavirkapur opened this issue Oct 21, 2024 · 5 comments
Open

StackAssertionError (while trying to signin) #310

suryavirkapur opened this issue Oct 21, 2024 · 5 comments

Comments

@suryavirkapur
Copy link

suryavirkapur commented Oct 21, 2024

Using the dev branch on my Mac.

Node and PNPM Versions

suryavirkapur@Suryavirs-MacBook-Pro stack % pnpm -v
9.4.0
suryavirkapur@Suryavirs-MacBook-Pro stack % node -v
v22.2.0

Error:

StackAssertionError: Uncaught error in asynchronous function: KnownError<USER_EMAIL_ALREADY_EXISTS>: User already exists.

This is likely an error in Stack. Please make sure you are running the newest version and report it.
    at eval (promises.js:125:26)Caused by: KnownError<USER_EMAIL_ALREADY_EXISTS>: User already exists.
    at KnownError.fromJson (known-errors.js:42:24)
    at StackClientInterface._processResponse (clientInterface.js:279:38)
    at async StackClientInterface.sendClientRequestInner (clientInterface.js:228:30)
    at async Object.retry (results.js:122:21)
    at async StackClientInterface._networkRetry (clientInterface.js:72:31)
    at async StackClientInterface.sendClientRequest (clientInterface.js:135:16)
    at async StackClientInterface.sendClientRequestAndCatchKnownError (clientInterface.js:146:30)
    at async StackClientInterface.sendMagicLinkEmail (clientInterface.js:328:21)
    at async __StackClientAppImpl.sendMagicLinkEmail (stack-app.ts:1100:12)
    at async onSubmit (magic-link-sign-in.tsx:94:18)
    at async eval (index.esm.mjs:2256:17) Object �[0m Error: This error was caught by DevErrorNotifier, and the original stacktrace is below.
    at console.<computed> (dev-error-notifier.tsx:18:25)
    at console.error (index.js:103:26)
    at eval (errors.js:36:13)
    at captureError (errors.js:44:9)
    at eval (promises.js:132:25)
@fomalhautb
Copy link
Contributor

fomalhautb commented Oct 21, 2024

What is the code that produces this? How can I reproduce it?

@suryavirkapur
Copy link
Author

suryavirkapur commented Oct 21, 2024

Followed development intructions on README.md: clone repo, switch .env.development to .env.local, and then run the project.

http://localhost:8101/handler/sign-in

Login via Email Magic Link

stackframe/stack-backend:dev: [dev] [    ERR] [xfjenwzm9aqkbsvx] POST http://localhost:8102/api/v1/auth/otp/sign-in: Internal Server Error. The error message follows, but will be stripped in production. TypeError: Cannot read properties of undefined (reading '0')
@stackframe/stack-backend:dev: [dev]     at isInsideNodeModules (node:internal/util:511:17)
@stackframe/stack-backend:dev: [dev]     at showFlaggedDeprecation (node:buffer:178:8)
@stackframe/stack-backend:dev: [dev]     at new Buffer (node:buffer:266:3)
@stackframe/stack-backend:dev: [dev]     at BN.toArrayLike (webpack-internal:///(rsc)/../../node_modules/.pnpm/[email protected]/node_modules/bn.js/lib/bn.js:546:15)
@stackframe/stack-backend:dev: [dev]     at BN.toBuffer (webpack-internal:///(rsc)/../../node_modules/.pnpm/[email protected]/node_modules/bn.js/lib/bn.js:531:17)
@stackframe/stack-backend:dev: [dev]     at getPrivateJwk (webpack-internal:///(rsc)/../../packages/stack-shared/dist/utils/jwt.js:90:85)
@stackframe/stack-backend:dev: [dev]     at async signJWT (webpack-internal:///(rsc)/../../packages/stack-shared/dist/utils/jwt.js:59:74)
@stackframe/stack-backend:dev: [dev]     at async generateAccessToken (webpack-internal:///(rsc)/./src/lib/tokens.tsx:100:16)
@stackframe/stack-backend:dev: [dev]     at async createAuthTokens (webpack-internal:///(rsc)/./src/lib/tokens.tsx:113:25)```



Broswer Console Dump:

https://pastebin.com/6DpbapPY

@fomalhautb
Copy link
Contributor

Followed development intructions on README.md: clone repo, switch .env.development to .env.local, and then run the project.

http://localhost:8101/handler/sign-in

Login via Email Magic Link

stackframe/stack-backend:dev: [dev] [    ERR] [xfjenwzm9aqkbsvx] POST http://localhost:8102/api/v1/auth/otp/sign-in: Internal Server Error. The error message follows, but will be stripped in production. TypeError: Cannot read properties of undefined (reading '0')
@stackframe/stack-backend:dev: [dev]     at isInsideNodeModules (node:internal/util:511:17)
@stackframe/stack-backend:dev: [dev]     at showFlaggedDeprecation (node:buffer:178:8)
@stackframe/stack-backend:dev: [dev]     at new Buffer (node:buffer:266:3)
@stackframe/stack-backend:dev: [dev]     at BN.toArrayLike (webpack-internal:///(rsc)/../../node_modules/.pnpm/[email protected]/node_modules/bn.js/lib/bn.js:546:15)
@stackframe/stack-backend:dev: [dev]     at BN.toBuffer (webpack-internal:///(rsc)/../../node_modules/.pnpm/[email protected]/node_modules/bn.js/lib/bn.js:531:17)
@stackframe/stack-backend:dev: [dev]     at getPrivateJwk (webpack-internal:///(rsc)/../../packages/stack-shared/dist/utils/jwt.js:90:85)
@stackframe/stack-backend:dev: [dev]     at async signJWT (webpack-internal:///(rsc)/../../packages/stack-shared/dist/utils/jwt.js:59:74)
@stackframe/stack-backend:dev: [dev]     at async generateAccessToken (webpack-internal:///(rsc)/./src/lib/tokens.tsx:100:16)
@stackframe/stack-backend:dev: [dev]     at async createAuthTokens (webpack-internal:///(rsc)/./src/lib/tokens.tsx:113:25)```



Broswer Console Dump:

https://pastebin.com/6DpbapPY

Are you sure that you didn't create a user with the same email before? I can't reproduce this problem

@suryavirkapur
Copy link
Author

Just tried singning up with a new email. Same issue.

@suryavirkapur
Copy link
Author

suryavirkapur commented Oct 21, 2024

packages/stack-shared/src/utils/jwt.tsx at Line 35:

  issuer: string,
  audience: string,
  payload: any,
  expirationTime?: string,
}) {
  const secret = getPerAudienceSecret({ audience: options.audience, secret: STACK_SERVER_SECRET });
  const kid = getKid({ secret });
  const privateJwk = await jose.importJWK(await getPrivateJwk(secret));
  return await new jose.SignJWT(options.payload)
    .setProtectedHeader({ alg: "ES256", kid })
    .setIssuer(options.issuer)
    .setIssuedAt()
    .setAudience(options.audience)
    .setExpirationTime(options.expirationTime || "5m")
    .sign(privateJwk);
}

Is returning an await on a promise.

export async function generateAccessToken(options: {
  projectId: string,
  useLegacyGlobalJWT: boolean,
  userId: string,
}) {
  waitUntil(logEvent([SystemEventTypes.UserActivity], { projectId: options.projectId, userId: options.userId }));

  if (options.useLegacyGlobalJWT) {
    return await legacySignGlobalJWT(
      jwtIssuer,
      { projectId: options.projectId, sub: options.userId },
      getEnvVariable("STACK_ACCESS_TOKEN_EXPIRATION_TIME", "10min")
    );
  } else {
    return await signJWT({
      issuer: jwtIssuer,
      audience: options.projectId,
      payload: { sub: options.userId },
      expirationTime: getEnvVariable("STACK_ACCESS_TOKEN_EXPIRATION_TIME", "10min"),
    });
  }
}

And here there is an await on an await ...

apps/backend/src/lib/tokens.tsx at Line 73:

This is not a function on the hot path, but thought would let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants