mirror of
https://github.com/jcreek/SvelteKitSaasBoilerplate.git
synced 2026-07-13 02:53:50 +00:00
feat(#74): Add token expiration for account deletion
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
-- Enable the "pg_cron" extension
|
||||||
|
create extension pg_cron with schema pg_catalog;
|
||||||
|
|
||||||
|
grant usage on schema cron to postgres;
|
||||||
|
grant all privileges on all tables in schema cron to postgres;
|
||||||
|
|
||||||
|
-- Create a function to delete expired tokens
|
||||||
|
CREATE OR REPLACE FUNCTION delete_expired_tokens()
|
||||||
|
RETURNS void LANGUAGE plpgsql AS $$
|
||||||
|
BEGIN
|
||||||
|
DELETE FROM account_deletion_requests
|
||||||
|
WHERE requested_at < NOW() - INTERVAL '24 hours';
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
-- Schedule the function to run every hour
|
||||||
|
SELECT cron.schedule(
|
||||||
|
'delete_expired_tokens',
|
||||||
|
'0 * * * *',
|
||||||
|
'CALL delete_expired_tokens()'
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user