openauth: Error: The browser was in an unknown state. This could be because certain cookies expired or the browser was switched in the middle of an authentication flow

Here is my setup:

infra/auth.ts

export const auth = new sst.aws.Auth("Auth", {
  authorizer: {
    handler: "packages/functions/src/auth.handler",
    link: [...allSecrets],
  },
  forceUpgrade: "v2",
});

auth.ts

import { handle } from "hono/aws-lambda";
import { issuer } from "@openauthjs/openauth";

import { subjects } from "./subjects";

import { PasswordProvider } from "@openauthjs/openauth/provider/password";
import { PasswordUI } from "@openauthjs/openauth/ui/password";
import { THEME_VERCEL } from "@openauthjs/openauth/ui/theme";
import { User } from "@mercur-connect/core/user";
import { MemoryStorage } from "@openauthjs/openauth/storage/memory";

const app = issuer({
  storage: MemoryStorage(),
  subjects,
  theme: THEME_VERCEL,
  allow: async () => true,
  providers: {
    password: PasswordProvider(
      PasswordUI({
        sendCode: async (email, code) => {
          console.log(email, code);
        },
      })
    ),
  },
  success: async (ctx, value) => {
    try {
      let user = await User.fromEmail(value.email).catch(() => null);

      if (!user) {
        user = await User.create({
          email: value.email,
        });
      }

      return ctx.subject("user", {
        id: user.id,
      });
    } catch (error) {
      console.error("error on success auth state", error);
      return new Response("something went wrong", { status: 500 });
    }
  },
});

export const handler = handle(app);

Error: Error: The browser was in an unknown state. This could be because certain cookies expired or the browser was switched in the middle of an authentication flow

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 16 (4 by maintainers)

Most upvoted comments

is anyone getting this when using a non-memory storage provider?

Thanks @jshimko for the detailed response and your willingness to help! I appreciate the insights into how OpenAuth handles redirects and storage.

We timeboxed getting OpenAuth running to 4 hours, including configuring our app and testing the example applications in the repo. Unfortunately, even the example apps failed to run out of the box, which wasn’t the best first-time experience. Given that and the added complexity from storage options and dependencies affecting our SBOM, we’ve decided not to move forward with OpenAuth at this time.

That said, I appreciate your input, and I hope the project continues to evolve - best of luck!

Same here, password provider work fine but code throw this error

Image