mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
feat(core): add expiresAt in response of verification record creation (#6686)
This commit is contained in:
parent
2fb85a229b
commit
6289433d8c
3 changed files with 48 additions and 12 deletions
|
@ -29,7 +29,21 @@
|
||||||
},
|
},
|
||||||
"responses": {
|
"responses": {
|
||||||
"201": {
|
"201": {
|
||||||
"description": "The verification record was created successfully."
|
"description": "The verification record was created successfully.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"verificationRecordId": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"expiresAt": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"422": {
|
"422": {
|
||||||
"description": "The password is invalid."
|
"description": "The password is invalid."
|
||||||
|
@ -57,7 +71,21 @@
|
||||||
},
|
},
|
||||||
"responses": {
|
"responses": {
|
||||||
"201": {
|
"201": {
|
||||||
"description": "The verification code has been successfully sent."
|
"description": "The verification code has been successfully sent.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"verificationRecordId": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"expiresAt": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"501": {
|
"501": {
|
||||||
"description": "The connector for sending the verification code is not configured."
|
"description": "The connector for sending the verification code is not configured."
|
||||||
|
|
|
@ -32,7 +32,7 @@ export default function verificationRoutes<T extends UserRouter>(
|
||||||
'/verifications/password',
|
'/verifications/password',
|
||||||
koaGuard({
|
koaGuard({
|
||||||
body: z.object({ password: z.string().min(1) }),
|
body: z.object({ password: z.string().min(1) }),
|
||||||
response: z.object({ verificationRecordId: z.string() }),
|
response: z.object({ verificationRecordId: z.string(), expiresAt: z.string() }),
|
||||||
status: [201, 422],
|
status: [201, 422],
|
||||||
}),
|
}),
|
||||||
async (ctx, next) => {
|
async (ctx, next) => {
|
||||||
|
@ -58,9 +58,12 @@ export default function verificationRoutes<T extends UserRouter>(
|
||||||
passwordVerification.verify(password)
|
passwordVerification.verify(password)
|
||||||
);
|
);
|
||||||
|
|
||||||
await insertVerificationRecord(passwordVerification, queries, userId);
|
const { expiresAt } = await insertVerificationRecord(passwordVerification, queries, userId);
|
||||||
|
|
||||||
ctx.body = { verificationRecordId: passwordVerification.id };
|
ctx.body = {
|
||||||
|
verificationRecordId: passwordVerification.id,
|
||||||
|
expiresAt: new Date(expiresAt).toISOString(),
|
||||||
|
};
|
||||||
ctx.status = 201;
|
ctx.status = 201;
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
|
@ -73,7 +76,7 @@ export default function verificationRoutes<T extends UserRouter>(
|
||||||
body: z.object({
|
body: z.object({
|
||||||
identifier: verificationCodeIdentifierGuard,
|
identifier: verificationCodeIdentifierGuard,
|
||||||
}),
|
}),
|
||||||
response: z.object({ verificationRecordId: z.string() }),
|
response: z.object({ verificationRecordId: z.string(), expiresAt: z.string() }),
|
||||||
status: [201, 501],
|
status: [201, 501],
|
||||||
}),
|
}),
|
||||||
async (ctx, next) => {
|
async (ctx, next) => {
|
||||||
|
@ -92,7 +95,7 @@ export default function verificationRoutes<T extends UserRouter>(
|
||||||
|
|
||||||
await codeVerification.sendVerificationCode();
|
await codeVerification.sendVerificationCode();
|
||||||
|
|
||||||
await insertVerificationRecord(
|
const { expiresAt } = await insertVerificationRecord(
|
||||||
codeVerification,
|
codeVerification,
|
||||||
queries,
|
queries,
|
||||||
// If the identifier is the primary email or phone, the verification record is associated with the user.
|
// If the identifier is the primary email or phone, the verification record is associated with the user.
|
||||||
|
@ -102,7 +105,10 @@ export default function verificationRoutes<T extends UserRouter>(
|
||||||
: undefined
|
: undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.body = { verificationRecordId: codeVerification.id };
|
ctx.body = {
|
||||||
|
verificationRecordId: codeVerification.id,
|
||||||
|
expiresAt: new Date(expiresAt).toISOString(),
|
||||||
|
};
|
||||||
ctx.status = 201;
|
ctx.status = 201;
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
|
|
|
@ -4,13 +4,14 @@ import { type KyInstance } from 'ky';
|
||||||
import { readConnectorMessage } from '#src/helpers/index.js';
|
import { readConnectorMessage } from '#src/helpers/index.js';
|
||||||
|
|
||||||
export const createVerificationRecordByPassword = async (api: KyInstance, password: string) => {
|
export const createVerificationRecordByPassword = async (api: KyInstance, password: string) => {
|
||||||
const { verificationRecordId } = await api
|
const { verificationRecordId, expiresAt } = await api
|
||||||
.post('api/verifications/password', {
|
.post('api/verifications/password', {
|
||||||
json: {
|
json: {
|
||||||
password,
|
password,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.json<{ verificationRecordId: string }>();
|
.json<{ verificationRecordId: string; expiresAt: string }>();
|
||||||
|
expect(expiresAt).toBeTruthy();
|
||||||
|
|
||||||
return verificationRecordId;
|
return verificationRecordId;
|
||||||
};
|
};
|
||||||
|
@ -19,7 +20,7 @@ const createVerificationCode = async (
|
||||||
api: KyInstance,
|
api: KyInstance,
|
||||||
identifier: { type: SignInIdentifier; value: string }
|
identifier: { type: SignInIdentifier; value: string }
|
||||||
) => {
|
) => {
|
||||||
const { verificationRecordId } = await api
|
const { verificationRecordId, expiresAt } = await api
|
||||||
.post('api/verifications/verification-code', {
|
.post('api/verifications/verification-code', {
|
||||||
json: {
|
json: {
|
||||||
identifier: {
|
identifier: {
|
||||||
|
@ -28,7 +29,8 @@ const createVerificationCode = async (
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.json<{ verificationRecordId: string }>();
|
.json<{ verificationRecordId: string; expiresAt: string }>();
|
||||||
|
expect(expiresAt).toBeTruthy();
|
||||||
|
|
||||||
return verificationRecordId;
|
return verificationRecordId;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue