I’m trying to work out the same thing so that I can hook Netlify Auth up to the User model.
I think that what I am going to try is to pull some sort of unique identifier from the netlify user object, and save that into my User model as a foreign key, something like:
model User {
id String @id @default(cuid())
email String
name String
// yadda yadda yadda
netifyUserId String
}
The creating the user in api/src//lib/auth.ts a bit like in this thread:
export const getCurrentUser = async ({ name, email }) => {
const user =
(await db.user.findOne({
where: { email },
})) || (await createUser(name, email))
return user
}
export const createUser = async (name, email) => {
return await db.user.create({
data: { name, email }
})
}
The part I need to work out to test this is what property of the netlify identity user object I can pull out to act as the unique Id, (not keen on email since this can change)
I think there is a GUID in there somewhere, I can see that in the decoded
object there is a field called sub
containing a guid like string which I suspect is Netlify’s identifier for that user.
More digging and some testing required.