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

Cannot leverage platform attribute in SvelteKit during sign-in #10779

Open
DakotaLarson opened this issue May 1, 2024 · 5 comments
Open

Cannot leverage platform attribute in SvelteKit during sign-in #10779

DakotaLarson opened this issue May 1, 2024 · 5 comments
Labels
bug Something isn't working svelte upstream The issue dervies from one of next-auth dependencies

Comments

@DakotaLarson
Copy link

Environment

  System:
    OS: Windows 10 10.0.19045
    CPU: (4) x64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz
    Memory: 5.84 GB / 15.94 GB
  Binaries:
    Node: 22.0.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.5.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (123.0.2420.97)
    Internet Explorer: 11.0.19041.3636
  npmPackages:
    @auth/sveltekit: ^1.0.1 => 1.0.1

Reproduction URL

https://github.com/DakotaLarson/authjs-bug

Describe the issue

When I sign in with google using SvelteKit & Auth.js, the event captured in the hook does not have the platform attribute present. I am hoping to leverage Cloudflare D1, which exposes an instance of the D1Database on the platform attribute under most requests. I need an instance of the D1Database to instantiate prisma client with the prisma d1 adapter, which takes the D1Database as an argument.

I have been getting around this issue using getPlatformProxy, a helper function from the wrangler package that returns the necessary data. This package is not compatible with cloudflare workers, so I need to get the D1Database object from another source.

How to reproduce

To reproduce, clone the authjs-bug repo that I linked, and update wrangler.toml with a real d1 database id. If you have wrangler cli installed, the command is wrangler d1 create . Then run npm run dev. If you navigate to localhost:5173, you should see a console statement indicating the platform attribute is present on the event captured by the hook. If you go through the sign in flow, you should see another console statement for the sign in event, which shows the platform attribute not being present.

Expected behavior

I expect the platform attribute to be present on the event captured by the hook.

@DakotaLarson DakotaLarson added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels May 1, 2024
@DakotaLarson DakotaLarson changed the title Cannot leverage platform attribute on Cannot leverage platform attribute in SvelteKit during sign-in May 1, 2024
@DakotaLarson
Copy link
Author

@ThangHuuVu
Copy link
Member

It seems like a binding issue with @sveltejs/adapter-cloudflare. Are you able to retrieve the platform attributes without using Auth.js, via a normal hook function?

@nathanblair
Copy link

Most of my reproductions and investigations lead me to believe this may indeed be a binding issue with the svelte cloudflare adapter. The event.platform is not populated at server-callback time either. @DakotaLarson I'll open a PR on your repro repo to help demonstrate that even in a raw sveltekit server hook handle function the event.platform attribute is empty.

@DakotaLarson
Copy link
Author

Appreciate your contribution! I just merged it in and am seeing that event.platform is indeed empty with a normal hook function. The only offering I have currently is this try on Discord. Forcing prerender = false seemed to hydrate the platform attribute for sign in requests. Functionality was still broken, but it was interesting to me. Will update here if I find anything interesting.

@ThangHuuVu ThangHuuVu added upstream The issue dervies from one of next-auth dependencies svelte and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels May 1, 2024
@nathanblair
Copy link

@ThangHuuVu - I was able to fix the issue. I'm not sure if what I've done is the most idiomatic way to achieve the desired behavior though.

I think what is needed is perhaps just some documentation updates regarding the expected configuration for the how auth callbacks work with sveltekit and auth.js.

Can you take a look over the repro repo and see what you think? If need be, I can look into updating the relevant sveltekit-framework documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working svelte upstream The issue dervies from one of next-auth dependencies
Projects
None yet
Development

No branches or pull requests

3 participants