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

Cloudflare D1 database adapter #5918

Closed
mackenly opened this issue Nov 29, 2022 · 16 comments · Fixed by #6953
Closed

Cloudflare D1 database adapter #5918

mackenly opened this issue Nov 29, 2022 · 16 comments · Fixed by #6953
Labels
adapters Changes related to the core code concerning database adapters enhancement New feature or request stale Did not receive any activity for 60 days

Comments

@mackenly
Copy link
Contributor

Description 📓

I'd like to add Cloudflare's D1 database service as a DB adapter.

How to reproduce ☕️

N/A

Contributing 🙌🏽

Yes, I am willing to help implement this feature in a PR

@mackenly mackenly added enhancement New feature or request triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Nov 29, 2022
@mackenly
Copy link
Contributor Author

I'll open a PR from here once I get some progress made: https://github.com/mackenly/next-auth

@mackenly
Copy link
Contributor Author

mackenly commented Nov 29, 2022

I'm probably missing something, but would there be any reason that all the adapters using the next-auth/adapters types module would be unable to find the module? I'm pretty much right out of the box after forking, following the contribution doc, and running the pnpm install script.

@ThangHuuVu ThangHuuVu added adapters Changes related to the core code concerning database adapters and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Dec 1, 2022
@ThangHuuVu
Copy link
Member

@mackenly what issue are you running to?

@mackenly
Copy link
Contributor Author

mackenly commented Dec 2, 2022

@mackenly what issue are you running to?

@ThangHuuVu
To eliminate any issues on my local system, I opened it up in a codespace and am having the same issue. After following the "Setting up local environment" steps in the contributing doc, when I try to open any of the existing adapter packages, their index.ts files can't find the adapters from next-auth/adapters.

I'm not super experienced in typescript; however, I feel like this probably isn't the expected behavior. Do the same things happen to you or am I doing something wrong? Thank you!

Open for screenshots In this codespace all I've done is clone/open it, run ```corepack enable pnpm```, ```pnpm --version```, and ```pnpm install```.

This screenshot is from the index.ts in the adapter-firebase package.

image

The same issue is present in that package's test. It's not finding next-auth.
image

This error is thrown when I tried to run pnpm install in the adapter-firebase directory.

@mackenly ➜ /workspaces/next-auth/packages/adapter-firebase (main ✗) $ pnpm install
Scope: all 20 workspace projects
 ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE  In : No matching version found for @next-auth@* inside the workspace

@jokester
Copy link

Hello @mackenly

Running pnpm run build in the repo root should fix the "Cannot find module" error.

Explanation: when everything goes right the import in adapter-firebase would be from REPO_ROOT/packages/adapter-firebase/node_modules/next-auth/adapters.d.ts, which (via symlink) goes to REPO_ROOT/packages/next-auth/adapters.d.ts, which is created by the build script.


I couldn't reproduce the  ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE  error but I'm guessing we don't need to pnpm install in packages/adapter-firebase. In a monorepo, pnpm install in repo root should be enough.

Hope it helps 👍

@jschlesser
Copy link
Contributor

jschlesser commented Mar 15, 2023

I opened a PR, the adapter works. It passes the adapter-test test suite, it works in a demo site I built locally based on the sveltekit framework dev app and I was able to deploy it to a cloudflare pages site.

There are 2 things that need resolving.

  1. Docs. Should they be for next-auth or authjs? If I could model the docs on an existing adapter is there one that is an ideal model?
  2. The tests use @miniflare/d1 as a mock for the d1 database. There is a bug in the currently published npm package. They merged a fix I made for it but haven't published it yet. Currently this PR is referencing a 'fixed' version (their current main branch) but on my personal npm scope @jschlesser. That's not ideal, but I'm not sure when they will publish it. We can go forward like this and change to the @miniflare scope when they publish or we can use patch-package or we can just put this on hold till they publish.

It would be great to get some feedback on using it from someone else like the OP @mackenly.
You can test the current code by cloning this project

@mackenly
Copy link
Contributor Author

Awesome, @jschlesser! Will definitely test and follow up with any feedback.

@jschlesser
Copy link
Contributor

jschlesser commented Mar 21, 2023

Good news, the miniflare maintainer finally published the fix to NPM today. I can fix # 2 of the issues that need resolving ☝️ . I'll get to that this week. For # 1, I'm going to move forward on the docs too vs waiting for a response from a maintainer. Im going to assume that the docs should be for next-auth for now.

@rozenmd
Copy link

rozenmd commented Apr 4, 2023

Hey @jschlesser / @mackenly,

I'm a Systems Engineer on the D1 team, this looks awesome! I'll add it to https://developers.cloudflare.com/d1/platform/community-projects/ once it gets merged

@jschlesser
Copy link
Contributor

@rozenmd , sounds good!

@stale
Copy link

stale bot commented Jun 9, 2023

It looks like this issue did not receive any activity for 60 days. It will be closed in 7 days if no further activity occurs. If you think your issue is still relevant, commenting will keep it open. Thanks!

@stale stale bot added the stale Did not receive any activity for 60 days label Jun 9, 2023
@stale
Copy link

stale bot commented Jun 17, 2023

To keep things tidy, we are closing this issue for now. If you think your issue is still relevant, leave a comment and we might reopen it. Thanks!

@stale stale bot closed this as completed Jun 17, 2023
@markdembo
Copy link

Hey! I am a Solutions Architect from Cloudflare (and love to code in my free time). Would love to see D1 support. Is there anything I/we from the Cloudflare side can do to support?

@ThangHuuVu
Copy link
Member

@markdembo @jschlesser I've just left some review comments in the PR, we can continue our discussion there!

@mackenly
Copy link
Contributor Author

#6953 was merged earlier in the month, adding D1 as an adapter. Thank you to all the contributors! Closing this issue.

See D1 adapter docs at: https://authjs.dev/reference/adapter/d1

@jschlesser
Copy link
Contributor

jschlesser commented Sep 29, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters enhancement New feature or request stale Did not receive any activity for 60 days
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants