next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

feat(adapters): add vanilla PostgreSQL adapter

Open jakecoppinger opened this issue 3 years ago โ€ข 6 comments

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

jakecoppinger avatar Jul 14 '22 12:07 jakecoppinger

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)

vercel[bot] avatar Jul 14 '22 12:07 vercel[bot]

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? :)

jakecoppinger avatar Jul 17 '22 12:07 jakecoppinger

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

balazsorban44 avatar Jul 19 '22 21:07 balazsorban44

What do you think about calling it @next-auth/pg-adapter? :slightly_smiling_face:

balazsorban44 avatar Jul 19 '22 22:07 balazsorban44

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 avatar Jul 20 '22 07:07 jakecoppinger

@jakecoppinger could you update the lock file so we can run tests in GitHub actions? (just run pnpm install and commit the result)

balazsorban44 avatar Jul 21 '22 15:07 balazsorban44

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 avatar Nov 15 '22 06:11 craig-bowers

@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?!

jakecoppinger avatar Dec 05 '22 09:12 jakecoppinger

found a fix now?

bonesoul avatar Feb 02 '23 14:02 bonesoul

LF this to get merged.

bonesoul avatar Feb 23 '23 08:02 bonesoul

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!

jakecoppinger avatar Feb 24 '23 05:02 jakecoppinger

Fixed! Needed to return id (using SQL command RETURNING) when creating a new user.

jakecoppinger avatar Feb 24 '23 05:02 jakecoppinger

Oops, meant to close the issue and not the PR.

Issue is now fixed. Rebased and ready for review & merge!

jakecoppinger avatar Feb 24 '23 05:02 jakecoppinger

eager now to get this merged :)

bonesoul avatar Feb 27 '23 23:02 bonesoul

Hi,

Any update to merge this PR?

LFCavalcanti avatar May 22 '23 22:05 LFCavalcanti

Any updates on this? Happy to help get this through the finish line!

robahtou avatar Jun 16 '23 15:06 robahtou

hi folks, I finished this PR in https://github.com/nextauthjs/next-auth/pull/8679, so I'm closing this one - thanks everyone!

ThangHuuVu avatar Sep 22 '23 07:09 ThangHuuVu