-
-
Notifications
You must be signed in to change notification settings - Fork 517
fix(core): return one-time token status as expired when expiration time is passed #7257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): return one-time token status as expired when expiration time is passed #7257
Conversation
COMPARE TO
|
Name | Diff |
---|---|
packages/core/src/libraries/one-time-token.ts | 📈 +135 Bytes |
packages/core/src/queries/one-time-tokens.ts | 📈 +976 Bytes |
packages/core/src/routes/one-time-tokens.ts | 📈 +12 Bytes |
packages/integration-tests/src/tests/api/one-time-tokens.test.ts | 📈 +1.01 KB |
db069f1
to
03776ba
Compare
03776ba
to
0d47ce5
Compare
const buildFindEntitiesSql = ( | ||
where: Partial<Pick<OneTimeToken, 'id' | 'token' | 'email' | 'status'>>, | ||
pagination?: { limit: number; offset: number } | ||
) => { | ||
const whereEntries = Object.entries(where).filter(([_, value]) => Boolean(value)); | ||
return sql` | ||
select | ||
${sql.join( | ||
Object.values(fields).filter((field) => field !== fields.status), | ||
sql`, ` | ||
)}, | ||
case | ||
when | ||
${fields.status} = ${OneTimeTokenStatus.Active} and | ||
${fields.expiresAt} < now() | ||
then ${OneTimeTokenStatus.Expired} | ||
else ${fields.status} | ||
end as "status" | ||
from ${table} | ||
${conditionalSql( | ||
whereEntries.length > 0 && whereEntries, | ||
(whereEntries) => | ||
sql`where ${sql.join( | ||
whereEntries.map(([column, value]) => | ||
conditionalSql(value, (value) => sql`${sql.identifier([column])} = ${value}`) | ||
), | ||
sql` and ` | ||
)}` | ||
)} | ||
order by ${fields.createdAt} desc | ||
${conditionalSql(pagination, ({ limit, offset }) => sql`limit ${limit} offset ${offset}`)} | ||
`; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also update the status? o/w the query response will be different than the DB data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid there will be a performance issue, since this logic is also used when fetching list, and there're chances that it ends up updating all the entities in the entire table. We can have an offline discussion if you want.
Summary
The
GET
one-time token APIs should automatically calculate the expiration time of the tokens, and modify the status in return data toexpired
when necessary.Previously, the GET APIs return the DB entries directly. However, since we only update the token status on verifying tokens, those unverified ones don't have the opportunity to have their status updated even if the expiration time has passed. Therefore, the token status might be out-of-date in such situations.
Testing
Integration tests added
Checklist
.changeset