feat: Implement user invitation backend functionality

This commit is contained in:
Faruk AYDIN
2024-07-08 17:36:18 +02:00
parent 0e4ac3b7f3
commit 3c3e6e4144
13 changed files with 166 additions and 27 deletions

View File

@@ -0,0 +1,23 @@
import User from '../../../../models/user.js';
export default async (request, response) => {
const { token, password } = request.body;
if (!token) {
throw new Error('Invitation token is required!');
}
const user = await User.query()
.findOne({ invitation_token: token })
.throwIfNotFound();
if (!user.isInvitationTokenValid()) {
throw new Error(
'Invitation link is not valid or expired. You can use reset password to get a new link.'
);
}
await user.acceptInvitation(password);
response.status(204).end();
};