Giter VIP home page Giter VIP logo

Comments (6)

nowaythatworked avatar nowaythatworked commented on July 17, 2024 1

Hi @junwen-k it´s important to know that next-auth and @auth/core is not the same. @auth/core originated from next-auth but is not an exact copy.

We published a new version of auth-astro yesterday, with this we also upgraded @auth/core to the latest version (0.5.1). Please try this out and make sure you also upgrade @auth/core in your project.

If your error still happens I´m not sure how much we can do here as it looks like the error lies in the core. Our package is just an Astro wrapper. Also you should not forget that @auth/core is still in pre-release, meaning it´s not stable yet.

from auth-astro.

junwen-k avatar junwen-k commented on July 17, 2024

Apparently, the typescript compiler error is coming from

image

Cannot find module 'next-auth/react' or its corresponding type declarations.ts(2307)

Could this be due to pnpm as well? Not sure if it is related to #9.

I've temporary resolved this by running:

$ pnpm add next-auth -D

I think it should be installed by default when installing this package.

from auth-astro.

nowaythatworked avatar nowaythatworked commented on July 17, 2024

#9

I never used pnpm before. Did something similar happen to you before in a different package? Did you
next-auth is listed as a devDependency in the project. This should be enough because we only import types from it. So it´s really weird that it´s not installing in your system.

from auth-astro.

nowaythatworked avatar nowaythatworked commented on July 17, 2024

Ok, we actually had our dependencies wrong. Putting it as devDependency was not enough and an error on our side. We still only import types so treeshaking should remove all unnecessary files when you build.

For the original issue about the unexptected response I need to do some more digging.
You´re saying the response is different from the documentation. Did you make sure that the version of the docs is the same as installed? Could you also please give more information on what the actual response is and what you´re expecting?

Thanks for bringing this to our attention.

from auth-astro.

junwen-k avatar junwen-k commented on July 17, 2024

@nowaythatworked Thank you for your reply. First time next-auth user here and I've been playing around with the configuration.

Apparently, my issue might be related to nextauthjs/next-auth#6512 and it seems like next-auth team did hi-jack the error on purpose. One way to test this is to create both projects with minimal setup and compare the response with auth-astro and next-auth.

According to the documentation here, the signIn method should return a Promise if redirect is set to false. This could be changed as I could not find this documentation in authjs.dev website. 🤔

Currently, I am handling error by using the response error query string. E.g,

utils/error.ts

// Based on specification:
// https://next-auth.js.org/configuration/pages#sign-in-page
export type SignInPageError =
  | 'OAuthSignin'
  | 'OAuthCallback'
  | 'OAuthCreateAccount'
  | 'EmailCreateAccount'
  | 'Callback'
  | 'OAuthAccountNotLinked'
  | 'EmailSignin'
  | 'CredentialsSignin'
  | 'SessionRequired'
  | 'Default';

export const getSignInPageError = (url: string) => {
  const searchParams = new URL(url).searchParams;
  const error = searchParams.get('error') as SignInPageError;
  const provider = searchParams.get('provider');
  return {
    error,
    provider,
  };
};

index.astro

<button id="login">Login Now!</button>

<script>
  const { signIn } = await import('auth-astro/client');
  document.getElementById('login')?.addEventListener('click', async () => {
    const resp = await signIn('credentials', {
      redirect: false,
      email: '[email protected]',
      password: 'MyPassword',
    });
    if (resp) {
      const { url } = (await resp?.json()) as { url: string };
      const { error } = getSignInPageError(url);
      if (error === 'CredentialsSignin') {
        // Handle error
      }
    }
  });
</script>

Of course, the best way to test this is by creating two minimal setup project for both next-auth and auth-astro and comparing the response.

from auth-astro.

junwen-k avatar junwen-k commented on July 17, 2024

@nowaythatworked Thanks for the prompt reply. I'll try with the latest package and see if it resolves the issue. Will reopen this issue should any problems arise.

from auth-astro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.