feat: add accept-invitation page

This commit is contained in:
Ali BARIN
2024-07-09 11:46:31 +00:00
committed by Faruk AYDIN
parent 3c3e6e4144
commit 9922033d33
13 changed files with 225 additions and 8 deletions

View File

@@ -12,9 +12,7 @@ export default async (request, response) => {
.throwIfNotFound();
if (!user.isInvitationTokenValid()) {
throw new Error(
'Invitation link is not valid or expired. You can use reset password to get a new link.'
);
return response.status(422).end();
}
await user.acceptInvitation(password);

View File

@@ -23,7 +23,7 @@ const createUser = async (_parent, params, context) => {
const userPayload = {
fullName,
email,
status: 'pending',
status: 'invited',
};
try {

View File

@@ -35,7 +35,7 @@ class User extends Base {
password: { type: 'string' },
status: {
type: 'string',
enum: ['active', 'pending'],
enum: ['active', 'invited'],
default: 'active',
},
resetPasswordToken: { type: ['string', 'null'] },
@@ -234,11 +234,12 @@ class User extends Base {
return await this.$query().patch({
invitationToken: null,
invitationTokenSentAt: null,
status: 'active',
password,
});
}
async isResetPasswordTokenValid() {
isResetPasswordTokenValid() {
if (!this.resetPasswordTokenSentAt) {
return false;
}
@@ -250,7 +251,7 @@ class User extends Base {
return now.getTime() - sentAt.getTime() < fourHoursInMilliseconds;
}
async isInvitationTokenValid() {
isInvitationTokenValid() {
if (!this.invitationTokenSentAt) {
return false;
}

View File

@@ -8,6 +8,7 @@ const userSerializer = (user) => {
email: user.email,
createdAt: user.createdAt.getTime(),
updatedAt: user.updatedAt.getTime(),
status: user.status,
fullName: user.fullName,
};