-
Your question What are you trying to do
If I'm approaching this the wrong way - I'd be grateful for pointers! Edit: Technically, what I'm looking for is an equivalent concept of Passport.js' Documentation feedback
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
Hmm - is this not a common enough use case? FWIW, the way that I am currently working around this issue is by creating my own middleware that runs after My middleware will look for the presence of the It doesn't feel very hacky - but it's definitely bypassing the intended mechanism for gating access to the application. The other draw back of my current solution is that I'm technically allowing any users to authenticate and thus create |
Beta Was this translation helpful? Give feedback.
-
My solution to a similar use case is to set a cookie inside the // [...nextauth].js
const getOptions = (req) => ({
// providers: [...],
// database: {...},
callbacks: {
signIn: async (user, account, profile) => {
const { invite_id } = req.cookies
// do something with invite_id
return true
},
},
})
export default (req, res) => NextAuth(req, res, getOptions(req)) |
Beta Was this translation helpful? Give feedback.
-
Here's one approach that worked for me, taken from the more opinionated create-t3-app // [...nextauth].ts
import NextAuth from "next-auth";
import { authOptions } from "./auth";
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST }; // auth.ts
...
export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
},
}),
},
};
... |
Beta Was this translation helpful? Give feedback.
-
This basic feature of passing a parameter from signIn to signIn in backend has been such a challenge. |
Beta Was this translation helpful? Give feedback.
My solution to a similar use case is to set a cookie inside the
getServerSideProps
method of the initial invite page. Then read the cookie from the callback (or thecreateUser
event):