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

Rethink WebAuthnStrategy.generateOptions #14

Closed
KubaJastrz opened this issue May 3, 2024 · 2 comments
Closed

Rethink WebAuthnStrategy.generateOptions #14

KubaJastrz opened this issue May 3, 2024 · 2 comments

Comments

@KubaJastrz
Copy link
Contributor

KubaJastrz commented May 3, 2024

Remix is planning to release Single Fetch functionality soon. It changes how the loader/action return values work, which makes remix-auth-webauthn incompatible with the current state of things.

Perhaps this is only temporary bug, but I'm encountering a problem with this code:

export const loader = async ({ request }) => {
	const user = await getUser(request);
	return webAuthnStrategy.generateOptions(request, sessionStorage, user);
}

I'm suspecting this is because webAuthnStrategy.generateOptions returns json response, although it should still technically work with the Single Fetch API.

My current workaround is as following:

export const loader = async ({ request, response }) => {
  const user = await getUser(request);
  const webAuthnResponse = await webAuthnStrategy.generateOptions(
    request,
    authSessionStorage,
    user
  );

  if (response) {
    webAuthnResponse.headers.forEach((value, key) => {
      response.headers.append(key, value);
    });
  }

  return webAuthnResponse.json();
};

Which looks kinda crazy, but works :D

@KubaJastrz
Copy link
Contributor Author

KubaJastrz commented May 3, 2024

Apparently this might be caused by vercel/remix#109

Edit: nevermind, seems unrelated

@KubaJastrz
Copy link
Contributor Author

It's also not playing well with the defineLoader helper. Not that it needs to, but just throwing it out there.

import { unstable_defineLoader as defineLoader } from "@remix-run/node";

export const loader = defineLoader(async ({ request }) => {
  const user = await getUser(request);

  return webAuthnStrategy.generateOptions(
    request,
    authSessionStorage,
    user
  );
});
Argument of type '({ request }: LoaderArgs) => Promise<TypedResponse<WebAuthnOptionsResponse & { extra: unknown; }>>' is not assignable to parameter of type 'Loader'.
  Type 'Promise<TypedResponse<WebAuthnOptionsResponse & { extra: unknown; }>>' is not assignable to type 'MaybePromise<DataFunctionReturnValue>'.
    Type 'Promise<TypedResponse<WebAuthnOptionsResponse & { extra: unknown; }>>' is not assignable to type '{ [key: string]: Serializable; [key: number]: Serializable; [key: symbol]: Serializable; } | Map<Serializable, Serializable> | Set<...> | Promise<...> | Promise<...>'.
      Type 'Promise<TypedResponse<WebAuthnOptionsResponse & { extra: unknown; }>>' is not assignable to type 'Promise<Serializable>'.
        Type 'TypedResponse<WebAuthnOptionsResponse & { extra: unknown; }>' is not assignable to type 'Serializable'.
          Type 'TypedResponse<WebAuthnOptionsResponse & { extra: unknown; }>' is not assignable to type '{ [key: string]: Serializable; [key: number]: Serializable; [key: symbol]: Serializable; }'.
            Property 'text' is incompatible with index signature.
              Type '() => Promise<string>' is not assignable to type 'Serializable'.ts(2345)

alexanderson1993 added a commit that referenced this issue May 24, 2024
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