🔑 feat: infinite key expiry (#3252)

This commit is contained in:
Marco Beretta 2024-07-05 17:15:09 +03:00 committed by GitHub
parent 1aad315de6
commit 1edbfdbce2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 23 deletions

View file

@ -21,16 +21,17 @@ const useUserKey = (endpoint: string) => {
const updateKey = useUpdateUserKeysMutation();
const checkUserKey = useUserKeyQuery(keyName);
const getExpiry = useCallback(() => {
if (checkUserKey.data) {
return checkUserKey.data.expiresAt;
return checkUserKey.data?.expiresAt || 'never';
}
}, [checkUserKey.data]);
const checkExpiry = useCallback(() => {
const expiresAt = getExpiry();
if (!expiresAt) {
return false;
return true;
}
const expiresAtDate = new Date(expiresAt);
@ -41,8 +42,8 @@ const useUserKey = (endpoint: string) => {
}, [getExpiry]);
const saveUserKey = useCallback(
(userKey: string, expiresAt: number) => {
const dateStr = new Date(expiresAt).toISOString();
(userKey: string, expiresAt: number | null) => {
const dateStr = expiresAt ? new Date(expiresAt).toISOString() : '';
updateKey.mutate({
name: keyName,
value: userKey,