feat(adapters): add vanilla PostgreSQL adapter
This is my first contribution to this repo - please let me know if there are things I'm missing/could improve!
All tests are passing.
โ๏ธ Reasoning
What changes are being made? What feature/bug is being fixed here?
๐งข Checklist
- [ x] Documentation
- [x] Tests
- [x] Ready to be merged
๐ซ Affected issues
Please scout and link issues that might be solved by this PR.
Fixes: https://github.com/nextauthjs/next-auth/issues/4897
๐ Resources
- Contributing guidelines
- Code of conduct
- Contributing to Open Source
The latest updates on your projects. Learn more about Vercel for Git โ๏ธ
| Name | Status | Preview | Comments | Updated |
|---|---|---|---|---|
| auth-docs | โ Ready (Inspect) | Visit Preview | ๐ฌ Add your feedback | Feb 24, 2023 at 5:52AM (UTC) |
| next-auth | โ Ready (Inspect) | Visit Preview | Feb 24, 2023 at 5:52AM (UTC) |
1 Ignored Deployment
| Name | Status | Preview | Comments | Updated |
|---|---|---|---|---|
| next-auth-docs | โฌ๏ธ Ignored (Inspect) | Feb 24, 2023 at 5:52AM (UTC) |
I'm still unable to solve a bug - createSession being called with an undefined userId: https://github.com/nextauthjs/next-auth/issues/4897
I initially thought I fixed it, but the issue persists. Are you able to reproduce and suggest a fix? :)
Just remembered, could you add the adapter to these lists:
For auto-labeling issues: https://github.com/nextauthjs/next-auth/blob/main/.github/issue-labeler.yml https://github.com/nextauthjs/next-auth/blame/main/.github/ISSUE_TEMPLATE/3_bug_adapter.yml#L23-L34
For auto-labeling PRs https://github.com/nextauthjs/next-auth/blob/main/.github/pr-labeler.yml
What do you think about calling it @next-auth/pg-adapter? :slightly_smiling_face:
Renamed to @next-auth/pg-adapter and updated the files you mentioned :)
I'm still stuck on this issue, any ideas? https://github.com/nextauthjs/next-auth/pull/4933#issuecomment-1186500481
@jakecoppinger could you update the lock file so we can run tests in GitHub actions? (just run pnpm install and commit the result)
Thanks for sharing your Postgres adapter! I used this as a starting point to set up NextAuth with pg-promise instead of pg and JavaScript instead of TS.
I am running into an issue though. When I use your adapter and try signing into my Google account via Google Provider I'm getting a new database entry into each of my users, accounts, and sessions tables, but the next-auth.session-token cookie is not getting set when I'm redirected back to http://localhost:3000 and when I try using useSession() on the front-end the status says I'm unauthenticated.
When I bypass the adapter it lets me log in just fine and I can use useSession() to see my Google email, image, etc., and it tells me that I'm authenticated. Obviously none of the data makes its way into Postgres with it bypassed though.
// adapter: PostgresAdapter(db),
Any idea on what the problem might be? I can share my [...nextauth].js or adapter file if you think it'll help.
@craig-bowers I haven't done any testing with anything but a standard email and password unfortunately, so no ideas on my end.
I'm still stuck on an issue (#4897), did you find a way to fix that by any chance?!
found a fix now?
LF this to get merged.
I tried to fix my PR based on the suggestion in this comment, but I'm not having any success unfortunately: https://github.com/nextauthjs/next-auth/issues/4897#issuecomment-1363414338
getSessionAndUser doesn't appear to be called. I've added logging in a test project to see what gets returned from the function but it isn't being called.
Any debugging help would be appreciated!
Fixed! Needed to return id (using SQL command RETURNING) when creating a new user.
Oops, meant to close the issue and not the PR.
Issue is now fixed. Rebased and ready for review & merge!
eager now to get this merged :)
Hi,
Any update to merge this PR?
Any updates on this? Happy to help get this through the finish line!
hi folks, I finished this PR in https://github.com/nextauthjs/next-auth/pull/8679, so I'm closing this one - thanks everyone!