I want only registered users to be allowed to login & only admin can register new users? (Next-Auth)

I don't want users to sign up themselves. I first need to check something manually, only then do i want to send them a sign-in link. I do know how to prevent anyone from logging in:
async signIn({ user, account, profile, email, credentials }) {
const userExists = await prisma.user.findUnique({
where: {
email: user.email
}
});

if (!userExists) {
return false;
}

return true;
}
}
async signIn({ user, account, profile, email, credentials }) {
const userExists = await prisma.user.findUnique({
where: {
email: user.email
}
});

if (!userExists) {
return false;
}

return true;
}
}
However, I now want a functionality for myself / for our backend, where I can put in the users email address and they'll get a sign-in link. Not sure how I would do that. So basically, only already registered users should be allowed to sign-in, but registration should only be up to me or an admin.
14 Replies
Pod
Pod2y ago
You could make a admin page with a mutation that would create the user entry, and then use whatever email service to send them an email to the site.
Lopen
Lopen2y ago
Ps: you can't findunique with email it must be id
plyglt
plyglt2y ago
why not? are u sure? it's working for me so far
Lopen
Lopen2y ago
Okay Not getting your point Then don't put a registration page then
plyglt
plyglt2y ago
I dont have one but sign-in by default in next-auth registers the user
Lopen
Lopen2y ago
What you should be doing is have like an admin dashboard
plyglt
plyglt2y ago
yeah exactly but I am not sure how to create the users for next-auth from my admin dashboard. can i just create a user with prisma, add them to the db and then next-auth will pick up on that? or will i need to go through the next-auth flow, because its creating other things in the background
Lopen
Lopen2y ago
To create a user you will need the email and whatever you require So the flow is still there But this time the flow will be on the admin dashboard
plyglt
plyglt2y ago
but it stills goes through next-auth, right? How do I trigger this then, as my admin dashboard will be on a different domain sorry i think i'm a bit stuck, it's probably super obvious
Lopen
Lopen2y ago
Is it a credentials based system? Next auth is usually for sign in To create a row its a function outside Been on a different domain doesn't mean anything You can still use same database
plyglt
plyglt2y ago
yeah true but i am using email magic links so next-auth will use whatever domain i am on to send the link, i think
Lopen
Lopen2y ago
Never used that But i think you can use the signIn function provided by next auth on the admin front-end to do all you need
plyglt
plyglt2y ago
ok i'll try that! thanks a lot
Lopen
Lopen2y ago
👍
Want results from more Discord servers?
Add your server