Skip to content

feat: add @auth/astro framework library - #9856

Open
theotterlord wants to merge 54 commits into
nextauthjs:mainfrom
theotterlord:auth-astro
Open

theotterlord wants to merge 54 commits into
nextauthjs:mainfrom
theotterlord:auth-astro

Conversation

@theotterlord

@theotterlord theotterlord commented Jan 30, 2024 •

Copy link
Copy Markdown

☕️ Reasoning

This PR is the next iteration of #6463

Introduces an Astro framework package. The package exposes an integration, along with helper methods for both server & client uses.

🧢 Checklist

  • Documentation (Note: The auth-astro.vercel.app autogenerated link doesn't have a deployed site. I'm assuming any deployed example will be hosted by this org)
  • Tests
  • Ready to be merged

🎫 Affected issues

📌 Resources

@vercel

vercel Bot commented Jan 30, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ❌ Failed (Inspect) Dec 3, 2024 7:28pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Dec 3, 2024 7:28pm

Comment thread apps/dev/astro/auth.config.ts Outdated
Comment thread packages/frameworks-astro/src/config.ts Outdated

@balazsorban44 balazsorban44 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Added some comments!

Besides those, have a look at https://github.com/nextauthjs/next-auth/blob/main/packages/utils/scripts/providers.js

Used eg. here:

"build": "pnpm clean && pnpm providers && tsc",
"clean": "rm -rf *.js *.d.ts* lib providers",
"dev": "pnpm providers && tsc -w",
"test": "vitest -c ../utils/vitest.config.ts",
"providers": "node ../utils/scripts/providers"

This way, users can import providers from @auth/astro/providers/* instead of having to install @auth/core!

Further, for other integrations support automatic environment variable inference by using the setEnvDefaults method like so

setEnvDefaults(process.env, config)

there is also createActionURL, a method from core that helps you create the url for the Request of Auth in a much less hacky way!

And lastly, the default basePath value is expected to be /auth, not /api/auth. (NextAuth.js is the only exception, since historically that was the default basePath there and we did not want to make this a breaking change in v5)

Could you incorporate these changes, and then make sure that the dev app and example app is also correctly updated? 🙏 Thanks!

Comment thread packages/frameworks-astro/module.d.ts Outdated
Comment thread packages/frameworks-astro/package.json Outdated
Comment thread packages/frameworks-astro/package.json Outdated
Comment on lines +13 to +17
".": "./src/index.ts",
"./config": "./src/config.ts",
"./client": "./src/client.ts",
"./server": "./src/server.ts",
"./middleware": "./middleware.ts"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
".": "./src/index.ts",
"./config": "./src/config.ts",
"./client": "./src/client.ts",
"./server": "./src/server.ts",
"./middleware": "./middleware.ts"
".": {
"types": "./index.d.ts",
"import": "./index.js"
},
"./config": {
"types": "./config.d.ts",
"import": "./config.js"
},
"./client": {
"types": "./client.d.ts",
"import": "./client.js"
},
"./server": {
"types": "./server.d.ts",
"import": "./server.js"
},
"./middleware": {
"types": "./middleware.d.ts",
"import": "./middleware.js"
},
"./adapters": {
"types": "./adapters.d.ts"
},
"./providers/*": {
"types": "./providers/*.d.ts",
"import": "./providers/*.js"
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Astro package doesn't require bundling, as all Astro projects (regardless of config) support TypeScript files. Is there still a reason to specify both types and import if they both lead to the same file?

Comment thread packages/frameworks-astro/package.json Outdated
Comment thread packages/frameworks-astro/tsconfig.json
Comment thread packages/frameworks-astro/src/server.ts Outdated
Co-authored-by: Balázs Orbán <info@balazsorban.com>
@NuroDev

NuroDev commented Mar 10, 2024

Copy link
Copy Markdown

Is there any further things blocking this from getting merged? I'd love to start using it

@ndom91

ndom91 commented Mar 11, 2024

Copy link
Copy Markdown
Contributor

There seem to be some merge conflicts. Otherwise it should be close. Needs another last going over, testing, etc.

@theotterlord

Copy link
Copy Markdown
Author

@ndom91 happy to resolve the conflict, seems to just be the pnpm-lock, so I'll try to do this tonight. Also, I have some notes from the last review in Discord that might be relevant when going over for another round of reviewing.

I also know there's been work on the framework guidelines? I've not been able to keep up as much as I wanted, so let me know if I'm missing anything important from those!

@ndom91

ndom91 commented Mar 13, 2024

Copy link
Copy Markdown
Contributor

@ndom91 happy to resolve the conflict, seems to just be the pnpm-lock, so I'll try to do this tonight. Also, I have some notes from the last review in Discord that might be relevant when going over for another round of reviewing.

I also know there's been work on the framework guidelines? I've not been able to keep up as much as I wanted, so let me know if I'm missing anything important from those!

Awesome, thanks! Yeah no I don't think there were any changes there. There's just this creating a framework pkg guidelines 👍

@vercel

vercel Bot commented Mar 13, 2024

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@jonaspm

jonaspm commented Oct 18, 2024

Copy link
Copy Markdown

I also hope this does get merged!

@dos41gw

dos41gw commented Oct 29, 2024

Copy link
Copy Markdown

Has anyone been able to run the fork with the installed PR? I'm stuck because the middleware isn't attaching due to an error in vite-plugin-astro-server/request.js: 'Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'auth:'.'

@jonaspm

jonaspm commented Oct 29, 2024 •

Copy link
Copy Markdown

Has anyone been able to run the fork with the installed PR? I'm stuck because the middleware isn't attaching due to an error in vite-plugin-astro-server/request.js: 'Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'auth:'.'

I have not, but seems that there is still some work being done by @theotterlord & @ndom91

@socket-security

socket-security Bot commented Oct 30, 2024 •

Copy link
Copy Markdown

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@astrojs/check@0.9.4 Transitive: filesystem +3 5.45 MB fredkschott, matthewp, natemoo-re
npm/@astrojs/node@9.0.0 None 0 27.8 kB matthewp
npm/@eslint/compat@1.1.1 None 0 47.7 kB eslintbot
npm/@eslint/js@9.9.1 None 0 14.2 kB eslintbot
npm/@graphql-codegen/cli@5.0.0 environment, filesystem, network, shell, unsafe +47 9.72 MB dotansimha
npm/@graphql-codegen/client-preset@4.1.0 Transitive: environment, eval, filesystem, shell, unsafe +36 11.5 MB dotansimha
npm/@graphql-typed-document-node/core@3.2.0 None 0 2.96 kB dotansimha
npm/@inkeep/widgets@0.2.289 Transitive: network +10 16.1 MB sarah-inkeep

🚮 Removed packages: npm/@auth/express@0.8.4, npm/@auth/unstorage-adapter@2.7.4, npm/@radix-ui/react-avatar@1.1.1, npm/@radix-ui/react-collapsible@1.1.1, npm/@radix-ui/react-dropdown-menu@2.1.2, npm/@radix-ui/react-navigation-menu@1.2.1, npm/@radix-ui/react-slot@1.1.0, npm/@simplewebauthn/server@9.0.3, npm/@types/express@4.17.21, npm/@types/morgan@1.9.9, npm/@types/react-dom@18.3.1, npm/@types/react@18.3.12, npm/@vercel/kv@1.0.1, npm/autoprefixer@10.4.20, npm/class-variance-authority@0.7.1, npm/express@4.21.1, npm/lucide-react@0.274.0, npm/morgan@1.10.0, npm/next-auth@5.0.0-beta.25, npm/next@15.0.3, npm/pug@3.0.3, npm/react-dom@18.3.1, npm/react@18.3.1, npm/tailwindcss-animate@1.0.7, npm/tailwindcss@3.4.15, npm/tsx@4.19.2, npm/unstorage@1.13.1

View full report↗︎

@RyzeKit

RyzeKit commented Nov 10, 2024

Copy link
Copy Markdown

I have moved away from authjs because I don't think this PR is ever going to be merged (there used to be a different one before this one)

Can you recommend good alternatives?

https://github.com/lucia-auth/lucia try this one its the other recommended framework for astro

Probably better that you don't do that.

lucia-auth/lucia#1707

I just finished converting my Astro starter kit to Lucia v4 (the latest version), and although it took some time, I would say it's a pretty good alternative. There are some examples that you can follow for guidance: https://github.com/orgs/lucia-auth/repositories?q=astro

@mseibert

Copy link
Copy Markdown

As a newbie, it's difficult for me to understand if this is going to be a feasible solution one day or not. It's ongoing for a long time and @NuroDev seems to be skeptical of it becoming a successful PR in this comment. Any official comment if this is going to be worked on and implemented?

@mseibert

Copy link
Copy Markdown

I do see that the official docs offer [auth-astro](https://www.npmjs.com/package/auth-astro) as an implementation. Does that resolve this here?

@dos41gw

dos41gw commented Jan 4, 2025

Copy link
Copy Markdown

package/auth-astro

i use this package, going fine. Kinda 'standalone' version. About this PR, guess, nobody believe, but it is still updated regularly.

@halvaradop halvaradop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimal changes

@@ -0,0 +1,98 @@
// THIS FILE IS AUTOGENERATED. DO NOT EDIT.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type is not required because it is already exported from the index.ts file. The type was separated into OAuthProviderId and EmailProviderId to improve provider inference as mentioned in PR #12249.

Note

These two types are located in the provider-types.ts file; however, this file is not included in the repository.

Comment on lines +1 to +3
{
"extends": "astro/tsconfigs/strict"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the include and exclude fields as recommended by Astro in the TypeScript guide

Comment on lines +1 to +3
{
"extends": "astro/tsconfigs/strict"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the include and exclude fields as recommended by Astro in the TypeScript guide

This branch had an error being deployed

1 failed deployment
Preview – auth-docs — 175dfa23 Deployed Dec 3, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.