nowaythatworked / auth-astro

Community maintained Astro integration of @auth/core
269 stars 39 forks source link

auth-astro components not being found #27

Open NachoVazquez opened 1 year ago

NachoVazquez commented 1 year ago

I'm getting some errors when trying to access the SignIn and SignOut components.

The code

---
import { SignIn, SignOut } from 'auth-astro/components';
---

<section>
  <h1 class="text-h1">Login</h1>
  <SignIn provider="google" />
  <SignOut />
</section>

The errors

Server Error (running on dev): 404 /h-astro/src/components/SignIn.astro

Client Error: GET p://localhost:3000/h-astro/src/components/SignIn.astro?astro&type=script&index=0&lang.ts net::ERR_ABORTED 404 (Not Found)

The Config

import { defineConfig } from 'astro/config';
import solid from '@astrojs/solid-js';
import react from '@astrojs/react';
import partytown from '@astrojs/partytown';
import sitemap from '@astrojs/sitemap';
import tailwind from '@astrojs/tailwind';
import cloudflare from '@astrojs/cloudflare';
import Google from '@auth/core/providers/google';
import auth from 'auth-astro';
import { loadEnv } from 'vite';

const env = loadEnv('production', process.cwd(), '');

export default defineConfig({
  outDir: '...',
  integrations: [
    react(),
    solid(),
    partytown(),
    sitemap(),
    tailwind(),
    auth({
      providers: [
        Google({
          clientId: env.GOOGLE_CLIENT_ID,
          clientSecret: env.GOOGLE_CLIENT_SECRET,
        }),
      ],
    }),
  ],
  output: 'server',
  adapter: cloudflare({ mode: 'advanced' }),
});
Benzolio commented 1 year ago

I've been getting the same ( from astro dev ) since I started refactoring a collection of related projects into a monorepo, with my Astro web UI now in as an npm workspace, something seems to have gone wrong with module resolution. There is no error in vscode while editing .astro pages that import the auth-astro components, but the components fail to load when running astro dev But, in my case, it builds without error, and astro preview renders the auth-astro components just fine with functioning signin and signout, no 404 errors. It would be really great to figure out where the import resolution is breaking in astro dev, maybe an alias in the vite config could fix it.

Edit: my situation my not be related, I just noticed my server errors include a /_modules/ path prefix that does not exist, and I'm not sure where that part is coming from

[serve]    404 /_modules/auth-astro/src/components/SignIn.astro
[serve]    404 /_modules/auth-astro/src/components/SignOut.astro

But still, it's only an issue for me while running as astro dev and works fine in astro preview after astro build