TheOtterlord / starlight-auth

Starlight + Auth.js template
https://starlight-auth-development.vercel.app/
41 stars 3 forks source link

Resolved: auth-astro Dependency Conflict by Upgrading @auth/core #2

Open MaestroMiyagi opened 3 months ago

MaestroMiyagi commented 3 months ago

Describe the bug

When installing dependencies for an Astro project using auth-astro@4.1.2, I encountered an error due to a peer dependency conflict with @auth/core. The project used an older version of @auth/core (0.18.6), while auth-astro required at least version 0.32.0.

To Reproduce

  1. Create a new Astro project using the Starlight Auth template:

    npm create astro@latest -- --template TheOtterlord/starlight-auth
  2. In the prompt, select yes when asked to install the dependencies

  3. It should give you the next error

    npm error code ERESOLVE
    npm error ERESOLVE unable to resolve dependency tree
    npm error
    npm error While resolving: starlight-auth@0.0.1
    npm error Found: @auth/core@0.18.6
    npm error node_modules/@auth/core
    npm error   @auth/core@"^0.18.6" from the root project
    npm error
    npm error Could not resolve dependency:
    npm error peer @auth/core@"^0.32.0" from auth-astro@4.1.2
    npm error node_modules/auth-astro
    npm error   auth-astro@"^4.1.1" from the root project
    npm error
    npm error Fix the upstream dependency conflict, or retry
    npm error this command with --force or --legacy-peer-deps
    npm error to accept an incorrect (and potentially broken) dependency resolution.
    npm error
    npm error

    How to fix it

  4. Create a new Astro project using the Starlight Auth template:

    npm create astro@latest -- --template TheOtterlord/starlight-auth
  5. In the prompt, select no when asked to install the dependencies

  6. Upgrade @auth/core to a compatible version:

    npm install @auth/core@^0.32.0

    Expected behavior

Dependencies should install without errors after upgrading @auth/core.

I hope this helps anyone having this problem

Additional context

Astro version: 4.5.17 Node.js version: v22.5.1 Operating system: Ubuntu 22.04.4 LTS

arnoan commented 4 weeks ago

@MaestroMiyagi Thank you for creating this issue and also documenting the fix. I initially encountered the same error, and now also got the template running with the updated version of @auth/core

I tried a proof of concept with GitHub OAuth provider and managed to get the login & logout working as intended. However the pages of the starlight documentation don't seem to be affected by the login state as represented by the session object.

The logic in src/lib/auth.ts doesn't seem to take effect. So even without being logged in/authenticated I can access the example doc pages that should be protected.

Did you eventually get the core functionality of protecting starlight pages to work as intended?

@TheOtterlord Is this project still maintained/functional or is it possible that with newer versions of the Astro dependencies your initial logic got broken? As it stands right now, I haven't been able to make my envisioned setup work (protect individual pages/routes in a Starlight docs site).

Thank you for building and sharing this template. I would be grateful for a quick indication whether this is still maintained/intended to work, or any other pointers you might have.

Many thanks, Arno