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

feat(adapters): update fauna adapter for fql v10

Open employee451 opened this issue 1 year ago โ€ข 7 comments

This PR tries to do the same as https://github.com/nextauthjs/next-auth/pull/8403. Rather than make a PR to @linzjax's branch, i thought it would be easier to open a new PR.

โ˜•๏ธ Reasoning

Fauna's new query language, FQL v10, has been out for a while. This PR updates adapter-fauna to use FQL v10 and the new conventions that have come from Fauna's side.

Breakdown of changes:

  • Use singular, uppercase names for collections (this is the new naming schema Fauna uses in their examples)
  • Stop using fauna-schema-migrate, and instead use the Fauna CLI and FSL for defining the collections and indexes
  • Switch from the faunadb to the fauna package and refactor all queries from FQL v4 to FQL v10
  • Update the documentation and add a "Migrating from v1" section

๐Ÿงข Checklist

  • [x] Documentation
  • [x] Tests
  • [x] Ready to be merged

๐ŸŽซ Affected issues

Fixes: https://github.com/nextauthjs/next-auth/issues/8394

๐Ÿ“Œ Resources

employee451 avatar Jan 29 '24 13:01 employee451

The latest updates on your projects. Learn more about Vercel for Git โ†—๏ธŽ

Name Status Preview Comments Updated (UTC)
auth-docs โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Mar 1, 2024 4:42pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs โฌœ๏ธ Ignored (Inspect) Visit Preview Mar 1, 2024 4:42pm

vercel[bot] avatar Jan 29 '24 13:01 vercel[bot]

Hi @ndom91 & @balazsorban44. It would be amazing if we could get this merged. We are currently migrating our app to next-auth and we want to use the new naming conventions Fauna uses for collections. The tests are all passing๐ŸŒž Thanks for your work on Auth.js!

employee451 avatar Feb 01 '24 12:02 employee451

@employee451 is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Feb 02 '24 09:02 vercel[bot]

๐Ÿšจ Potential security issues detected. Learn more about Socket for GitHub โ†—๏ธŽ

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSource
Install scripts npm/[email protected]
  • Install script: postinstall
  • Source: echo "[svelte-preprocess] Don't forget to install the preprocessors packages that will be used: sass, stylus, less, postcss & postcss-load-config, coffeescript, pug, etc..."
Install scripts npm/@sveltejs/[email protected]
  • Install script: postinstall
  • Source: node postinstall.js
Telemetry npm/[email protected]
  • Note: Can be disabled by setting the environment variable NEXT_TELEMETRY_DISABLED=1 . See https://nextjs.org/telemetry for more information
Telemetry npm/[email protected]
  • Note: Can be disabled by setting the environment variable NEXT_TELEMETRY_DISABLED=1 . See https://nextjs.org/telemetry for more information

View full reportโ†—๏ธŽ

Next steps

What is an install script?

Install scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.

Packages should not be running non-essential scripts during install and there are often solutions to problems people solve with install scripts that can be run at publish time instead.

What is telemetry?

This package contains telemetry which tracks how it is used.

Most telemetry comes with settings to disable it. Consider disabling telemetry if you do not want to be tracked.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

socket-security[bot] avatar Feb 04 '24 02:02 socket-security[bot]

@balazsorban44 Thanks for your help with this PR. The tests should be passing now (can you confirm?). Except for the two unresolved conversations above, we should be ready to merge

employee451 avatar Feb 05 '24 09:02 employee451

Sorry if I'm being pushy. We really want to get this merged so we can switch from Auth0 to next-auth with an email provider. I've made the changes you requested and the tests are passing properly now โœ… ๐ŸŒž @balazsorban44 @ndom91 @ThangHuuVu

Comments to look at:

  • https://github.com/nextauthjs/next-auth/pull/9849#discussion_r1477870614
  • https://github.com/nextauthjs/next-auth/pull/9849#discussion_r1479334645

employee451 avatar Feb 18 '24 11:02 employee451

Hey @employee451 first of all thanks for the contribution!

Can you give me a short run down of the implications of this for existing fauna adapter users?

ndom91 avatar Feb 19 '24 11:02 ndom91

Hey @employee451 first of all thanks for the contribution!

Can you give me a short run down of the implications of this for existing fauna adapter users?

Thanks for your reply @ndom91! Existing Fauna adapter users will need to use a Fauna client from the new fauna library instead of the old faunadb. Additionally, they will have to rename the auth collections that the adapter uses. This is explained in the new "Migrating from v1" section I've added to the adapter docs:

In v2, we've renamed the collections to use uppercase naming, in accordance with Fauna best practices. If you're migrating from v1, you'll need to rename your collections to match the new naming scheme.
Additionally, we've renamed the indexes to match the new method-like index names. Please see above for the new index definitions.

employee451 avatar Feb 22 '24 09:02 employee451

LGTM ๐ŸŽ‰

Thanks! What needs to happen to get this merged? Do we need @balazsorban44 to approve the changes?

employee451 avatar Mar 01 '24 16:03 employee451

@employee451 what do you think about this migration script in FQL? Looks like it should do the trick to me:

Collection.byName("accounts")!.update({
  name: "Account"
  indexes: {
    byUserId: {
        terms: [{ field: "userId" }]
    },
    byProviderAndProviderAccountId: {
        terms: [{ field: "provider" }, { field: "providerAccountId" }]
    }
  }
})
Collection.byName("sessions")!.update({
  name: "Session",
  indexes: {
    bySessionToken: {
        terms: [{ field: "sessionToken" }]
    },
    byUserId: {
        terms: [{ field: "userId" }]
    },
  }
})
Collection.byName("users")!.update({
  name: "User",
  indexes: {
    byEmail: {
        terms: [{ field: "email" }]
    },
  }
})
Collection.byName("verification_tokens")!.update({
  name: "VerificationToken",
  indexes: {
    byIdentifierAndToken: {
        terms: [{ field: "identifier" }, { field: "token" }]
    },
  }
})

I can merge it, but we'll need someone else to cut a release. We plan on doign that this weekend anyway. No need to tag anyone else :wink: :+1:

ndom91 avatar Mar 01 '24 16:03 ndom91

@employee451 what do you think about this migration script in FQL? Looks like it should do the trick to me:

Collection.byName("accounts")!.update({
  name: "Account"
  indexes: {
    byUserId: {
        terms: [{ field: "userId" }]
    },
    byProviderAndProviderAccountId: {
        terms: [{ field: "provider" }, { field: "providerAccountId" }]
    }
  }
})
Collection.byName("sessions")!.update({
  name: "Session",
  indexes: {
    bySessionToken: {
        terms: [{ field: "sessionToken" }]
    },
    byUserId: {
        terms: [{ field: "userId" }]
    },
  }
})
Collection.byName("users")!.update({
  name: "User",
  indexes: {
    byEmail: {
        terms: [{ field: "email" }]
    },
  }
})
Collection.byName("verification_tokens")!.update({
  name: "VerificationToken",
  indexes: {
    byIdentifierAndToken: {
        terms: [{ field: "identifier" }, { field: "token" }]
    },
  }
})

I can merge it, but we'll need someone else to cut a release. We plan on doign that this weekend anyway. No need to tag anyone else ๐Ÿ˜‰ ๐Ÿ‘

The script looks good๐Ÿ˜„

employee451 avatar Mar 01 '24 16:03 employee451

Ah forgot to drop the existing indexes, here's a slightly updated one:

Collection.byName("accounts")!.update({
  name: "Account"
  indexes: {
    byUserId: {
        terms: [{ field: "userId" }]
    },
    byProviderAndProviderAccountId: {
        terms: [{ field: "provider" }, { field: "providerAccountId" }]
    },
    account_by_provider_and_provider_account_id: null,
    accounts_by_user_id: null
  }
})
Collection.byName("sessions")!.update({
  name: "Session",
  indexes: {
    bySessionToken: {
        terms: [{ field: "sessionToken" }]
    },
    byUserId: {
        terms: [{ field: "userId" }]
    },
    session_by_session_token: null,
    sessions_by_user_id: null
  }
})
Collection.byName("users")!.update({
  name: "User",
  indexes: {
    byEmail: {
        terms: [{ field: "email" }]
    },
    user_by_email: null
  }
})
Collection.byName("verification_tokens")!.update({
  name: "VerificationToken",
  indexes: {
    byIdentifierAndToken: {
        terms: [{ field: "identifier" }, { field: "token" }]
    },
    verification_token_by_identifier_and_token: null
  }
})

If you also think its good, lets include it in the docs. What do you think?

ndom91 avatar Mar 01 '24 16:03 ndom91

If you also think its good, lets include it in the docs. What do you think?

Oh right, good idea to drop the previous indexes. Approved by me. Let's include it in the docs๐Ÿ‘

employee451 avatar Mar 01 '24 16:03 employee451

Awesome, if you cuold add that to this PR, i'll approve it again :+1:

ndom91 avatar Mar 01 '24 16:03 ndom91

Awesome, if you cuold add that to this PR, i'll approve it again ๐Ÿ‘

Done!

employee451 avatar Mar 01 '24 16:03 employee451

New and removed dependencies detected. Learn more about Socket for GitHub โ†—๏ธŽ

Package New capabilities Transitives Size Publisher
npm/@prettier/[email protected] environment Transitive: eval +20 1.93 MB shinigami92
npm/@radix-ui/[email protected] None +4 120 kB benoitgrelard
npm/@radix-ui/[email protected] None +8 205 kB benoitgrelard
npm/@radix-ui/[email protected] None +35 1.86 MB benoitgrelard
npm/@radix-ui/[email protected] None +14 610 kB benoitgrelard
npm/@radix-ui/[email protected] Transitive: environment +8 2.06 MB benoitgrelard
npm/@sveltejs/[email protected] environment Transitive: eval, filesystem, network, shell, unsafe +51 13.9 MB svelte-admin
npm/@sveltejs/[email protected] environment, eval Transitive: filesystem, network, shell, unsafe +50 13.9 MB svelte-admin
npm/@sveltejs/[email protected] Transitive: environment, eval, filesystem, network, shell, unsafe +34 12.9 MB svelte-admin
npm/@types/[email protected] None +9 106 kB types
npm/@types/[email protected] None 0 13.9 kB types
npm/@types/[email protected] None +1 3.96 MB types
npm/@types/[email protected] None +4 1.72 MB types
npm/@types/[email protected] None +3 1.69 MB types
npm/[email protected] environment Transitive: filesystem, shell +7 2.65 MB ai
npm/[email protected] None +1 15.7 kB joebell93
npm/[email protected] environment, filesystem Transitive: shell +28 14.4 MB gustavohenke
npm/[email protected] environment, filesystem Transitive: eval, shell, unsafe +71 9.88 MB eslintbot
npm/[email protected] environment, filesystem, network Transitive: eval, unsafe +48 1.77 MB ulisesgascon
npm/[email protected] None 0 19.6 MB ericfennis
npm/[email protected] eval Transitive: environment +6 124 kB dougwilson
npm/[email protected] environment, filesystem, network, shell, unsafe +14 93.5 MB vercel-release-bot
npm/[email protected] environment, filesystem, shell Transitive: network +12 499 kB remy
npm/[email protected] Transitive: environment, eval +21 4.43 MB thecrypticace
npm/[email protected] environment, eval, filesystem +50 6.7 MB pug-bot
npm/[email protected] environment +4 4.93 MB gnoff
npm/[email protected] environment +2 337 kB gnoff
npm/[email protected] Transitive: environment, eval, filesystem, unsafe +77 57.6 MB svelte-language-tools-deploy
npm/[email protected] Transitive: unsafe +20 6.42 MB svelte-admin
npm/[email protected] None 0 18.1 kB thejameskyle
npm/[email protected] environment, filesystem Transitive: network, shell, unsafe +69 13.2 MB adamwathan
npm/[email protected] None 0 40.6 MB typescript-bot
npm/[email protected] environment, eval, filesystem, network, shell, unsafe +7 6.28 MB vitebot

๐Ÿšฎ Removed packages: npm/@actions/[email protected], npm/@auth/[email protected], npm/@auth/[email protected], npm/@aws-sdk/[email protected], npm/@aws-sdk/[email protected]

View full reportโ†—๏ธŽ

socket-security[bot] avatar Mar 01 '24 16:03 socket-security[bot]

Okay merged it, thanks again! Like I said, we plan on getting a release out this weekend, so I'll keep you posted :+1:

ndom91 avatar Mar 01 '24 16:03 ndom91

Thank you so much! I'm excited for v5๐Ÿƒ

employee451 avatar Mar 01 '24 17:03 employee451

@employee451 available in @auth/[email protected] now :tada:

ndom91 avatar Mar 02 '24 14:03 ndom91