mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-08-20 12:00:32 +08:00
Implementing a bare bones interaction with the task backend
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user