-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Make next-auth
framework agnostic (Vite, Vue, Express...)
#2294
Comments
I'm very hopeful about this. We might have to do small adjustments, but I think in most cases, a tiny wrapper on top of I already started to decouple/better namespace our client code, in v4 it will be under See #1473 |
Exciting 😍. Will I then be able to use NextAuth.js in a let's say Vite + Vue app? I'm developing a framework ("Vike") on top of Vite + vite-plugin-ssr + RPC and I'd love to offer authentication to both my React and Vue users with NextAuth.js. Thanks for your wonderful work, it's lovely to see the JS ecosystem maturing. |
If we rewrite the backend a bit, as long as your framework can set cookies and do redirects and handle basic POST/GET requests, it should be good. We would need to separate the I liked the Sveltekit endpoint approach: |
Neat & yes, the backend integration should work then. How about Vue? You mentioned:
Will we be able to have a |
Yes, that would be easy I think. Here is the source code for the react specific frontend: https://github.com/nextauthjs/next-auth/blob/next/src/client/react.js We still have to work out some small things like tab syncing and invalidation of the session, but other than that it should not be hard, hopefully. |
👌. Had a quick look over the source and yea should be fairly easy to port it to Vue's composition API; there aren't that many React specific things going on. AFACIT a common module that factors out the React/view-framework agnostic code should make porting quite easy. Can't wait to see NextAuth.js to become the de facto standard — Vite & Vue users will love it :-). |
It's quite amazing that you don't even need to install |
@wobsoriano Wow neat... would you be up to develop some Vue composition functions? Basically like |
That's awesome @wobsoriano! Looking forward to set some time aside for this enhancement, so we can start the expansion! I will probably need some help for the Vue client. |
Copied contents of Most if it are working now - // store/index.js
export const actions = {
async nuxtServerInit({ commit }, { req }) {
try {
const session = await getSession({ req })
commit('SET_SESSION', session);
} catch (e) {
commit('SET_SESSION', null);
}
}
} <template>
<div>
<div v-for="provider in Object.values(providers)" :key="provider.id">
<button @click="signIn(provider.id)">Sign in with {{ provider.name }}</button>
</div>
</div>
</template>
<script>
import { defineComponent } from '@nuxtjs/composition-api';
import { getProviders, signIn } from '~/modules/next-auth/client';
export default defineComponent({
middleware: 'guest',
setup() {
return {
signIn
}
},
async asyncData() {
const providers = await getProviders()
return {
providers
}
}
})
</script> and adding configs directly to import Providers from 'next-auth/providers';
export default {
// other nuxt config
nextAuth: {
providers: [
Providers.GitHub({
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET
}),
],
}
} |
@wobsoriano Neat neat 👌. What was your reason to use Nuxt's composition API instead of Vue's one? What do you think of factoring out the common code between |
Actually published a simple Nuxt module for this that later we can add to next-auth/client since Nuxt 2.0 supports Vue 2 only |
Nice 👍. Ideally |
Yeah, the whole client.js file is copied |
I guess it should be easy to factor out the common code? The common code could then live at Thoughts? |
Pretty neat - looking to integrate Next-auth into an Express API, so would be happy to test this out and deliver feedback |
I think we can start adding integrations for vue/svelte in the beta branch |
I kindly ask anyone wanting to work on this to wait until v4 is released as stable! I have many ideas and future improvements planned, but v4 beta should be considered as a feature freeze, and no additional changes should be made apart from bug fixes. Keep an eye on the releases. That said, you can definitely start looking into this, but I cannot provide feedback until v4 is ready. |
👍 Is there an ETA for v4? |
It is currently in beta. The more people check it out/give feedback on what is missing/failing, the faster it will be to release it to stable. I have never worked on anything of this scale, and the responsibility is huge, so I want to make it right. |
I will. |
Are there some docs about extending NextAuth to add support for Vie, Vue, etc.? |
No, not that I'm aware of. Not sure where it could fit nicely, but feel free to open a PR on https://github.com/nextauthjs/docs |
next-auth
frameworkagnostic (Vite, Vue, Express...)next-auth
framework agnostic (Vite, Vue, Express...)
is it possible to export client utils? import {
BroadcastChannel,
CtxOrReq,
apiBaseUrl,
fetchData,
now,
NextAuthClientConfig,
} from './client' |
Yes, it is. Although I'll export them on the PR, but maybe under something like UPDATE: Newest version on the PR should have an export at |
That is really cool! 👏 I wonder if there is anything I should do/expose for this to be a viable base to build on top of. I would like to get the PR reviewed so we can get closer to a v4 stable release. It looks like you already have a working Nuxt & SvelteKit POC, which is awesome 😅 Svelte and Vue clients could follow. In short, a client in
Docs here: |
I think these functions can be used by Vue/Svelte (except useSession) |
And probably Do you want me to do anything more on the PR? |
all good for now :D |
I think it's still relevant :-) |
It is. I'm taking a small break from the project (low maintenance is still provided) for the holidays, and to be able to better focus on my new job. Will come back the next year. Cheers 🍻 |
That's actually good timing as we'll be able to show you the Vike + NextAuth integration next year :-). Happy holidays 🎄. |
I am using NextJS for the production app and Storybook for the UI testing solution and UI regression testing. Is it possible to use NextAuth currently already with v4 and Storybook? I couldn't find any pointers so far. |
Small update here, we are in the works to convert this repo to a monorepo that will contain all the projects like adapters, docs, and examples, with the core itself. this will open up for creating new packages for different frameworks. Once we are satisfied with the monorepo setup (#3650) we can get around this issue much more easily! |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Follow up of https://twitter.com/balazsorban44/status/1410641689715347461.
cc @s-kris @balazsorban44
next-auth
can actually already be used with Vite today thanks to https://github.com/s-kris/vite-ssr-next-auth.UPDATE FROM MAINTAINER:
Proof of concept:
v4 has been marked as stable, and the source code has been refactored to be Next.js API routes agnostic. It is still undocumented, but we are ready to discuss how to integrate with other frameworks in the open. If you are developing in one of those communities (Vue, Svelte etc.), feel free to reach out!
The text was updated successfully, but these errors were encountered: