import * as common from "https://deno.land/x/supabase_common/mod.ts"
const { TOTP} = common
const { createTOTP,verifyTOTP } = TOTP
// Create TOTP
const {secret:any,uri:string} = createTOTP(project_name,user_name,google2fa_secret)
// Verify TOTP
const isCodeCorrect = verifyTOTP(params.uri,params.google2fa_code)
Add database functions on supabase
- generate token
begin
return extensions.generate(
payload:= payload,
secret:= secret,
algorithm:= algorithm,
);
end;
- verify_token
declare
params json;
pass boolean;
begin
select payload,valid
into params,pass
from extensions.verify(
token:= token,
secret:= secret,
algorithm:= algorithm
);
return json_build_object(
'params',params,
'valid',pass
);
end;
Usage
const { generateToken,verifyToken } = common
// Generate token
const token = generateToken(payload,expires_in,supabaseClient)
// Verify token
const { params,valid } = verifyToken(token,supabaseClient)
const { password_hash, password_verify } = common
// Hash password
const hashedPassword = password_hash(password)
// Verify password
const isPasswordCorret = password_verify(params.login_password, adminInfo.login_hash)