Implementing a bare bones interaction with the task backend

This commit is contained in:
Keith Stevens
2022-12-17 14:20:39 +09:00
parent 668f81c5b2
commit 8617f5b239
6 changed files with 170 additions and 45 deletions
-41
View File
@@ -36,47 +36,6 @@ export const authOptions = {
return session;
},
},
events: {
/**
* When a new user signs in, we register them with the Labeler backend.
*/
async signIn({ user, account, profile, isNewUser }) {
if (!isNewUser) {
return;
}
try {
// Register the new user with the Labeler Backend.
const res = await fetch(`${process.env.FASTAPI_URL}/api/v1/labelers`, {
method: "POST",
headers: {
"X-API-Key": process.env.FASTAPI_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
discord_username: user.id,
display_name: user.name || user.email,
is_enabled: true,
notes: account.provider,
}),
});
if (res.status !== 200) {
console.error(res.statusText);
return;
}
// Update the User entry with the Labeler Backend's ID so we can
// reference it later.
const { id: labelerId } = await res.json();
await prisma.user.update({
where: { id: user.id },
data: {
labelerId,
},
});
} catch (error) {
console.error(error);
}
},
},
};
export default NextAuth(authOptions);