I have a supabase project where I want the users to be able to delete their account.
Every user has a profile in public.profiles. I thought I could let the users delete their profile and then handle the deletion of the account using a trigger.
So I created this:
CREATE OR REPLACE FUNCTION deleteUser() RETURNS TRIGGER AS $$
BEGIN
DELETE FROM auth.users WHERE auth.users.id = OLD.user_id;
RETURN OLD;
END $$ LANGUAGE 'plpgsql';
CREATE TRIGGER deleteUserTrigger
AFTER DELETE
ON public.profiles
FOR EACH ROW
EXECUTE PROCEDURE deleteUser();
In the supabase table-editor interface it works great, but when I delete an account through my application it fails with: code: "42501", message: "permission denied for table users".
const { error } = await client.from("profiles").delete().eq("user_id", user.id);
console.log(error)
Without the trigger there is no error and the profile is deleted (but the account persists obviously).
Any help would be much appreciated!
I found this but I'm not sure about it..
If anybody is having this same issue, it can be fixed by adding security definer
so the sql becomes this:
CREATE OR REPLACE FUNCTION deleteUser() RETURNS TRIGGER AS $$
BEGIN
DELETE FROM auth.users WHERE auth.users.id = OLD.user_id;
RETURN OLD;
END $$ LANGUAGE 'plpgsql' security definer;
CREATE TRIGGER deleteUserTrigger
AFTER DELETE
ON public.profiles
FOR EACH ROW
EXECUTE PROCEDURE deleteUser();
Related
I am trying to trigger an API call with Incident Sys_id as parameter, when an new incident gets created in Service Now.
(function executeRule(current, previous /*null when async*/) {
If(current.operation() == 'insert') ; {
//
}
// Add your code here
})(current, previous);
how can i achieve this ?
My api:
https://Demand.jitterbit.cc/defaultUrlPrefix/v1.0/snowSalesforceCaseCreate
you need to create rest message, and there you can use the method which you want to use(ex: post), and you can add the parameters that you want(ex: sys_id)..
later to that you can create Business Rule, in that business rule call the rest message and pass the parameters
I am trying to use the Delphi TREST components to connect to the HRMC VAT API.
I have got as far as obtaining access and refresh tokens, but I cannot get any further.
At the moment, I am trying to retrieve my obligations as follows:-
RESTClient := TRestClient.Create('https://test-api.service.hmrc.gov.uk/organisations/vat/666596898/obligations');
try
RESTRequest := TRESTRequest.Create(RESTClient);
RESTResponse := TRESTResponse.Create(RESTClient);
OAuth2 := TOAuth2Authenticator.Create(RESTClient);
with OAuth2 do
begin
AccessToken := <my access token>;
ResponseType := TOAuth2ResponseType(rtCODE);
TokenType := TOAuth2TokenType(ttBEARER);
end;
with RESTClient do
begin
Authenticator := OAuth2;
ContentType := 'application/json';
end;
with RESTRequest do
begin
Client := RESTClient;
Response := RESTResponse;
Accept := 'application/vnd.hmrc.1.0+json';
Params.AddItem('from', '2017-01-25', pkGETorPOST);
Params.AddItem('to', '2017-01-25', pkGETorPOST);
Execute;
end;
finally
RESTClient.DisposeOf;
end;
This particular code returns the error INVALID_DATE_RANGE. But depending on what dates I use, I also sometimes get CLIENT_OR_AGENT_NOT_AUTHORISED.
Can anyone shed any light on where I am going wrong?
Perhaps it doesn't like the start and end dates being the same? It does say invalid date RANGE rather than invalid dates.
I worked it out finally. It was a problem with my Test User credentials. I generated them from the HMRC website, but I discovered from other posts that there is a problem generating them that way. When I created a user via the API, it works fine!
I hope this helps someone.
I'm trying to build an app using oracle builder (oracle forms) and i want to know the user name after login, is there any option like sessions in (PHP/ JEE) to know who logged in my app?
To get User's Login&App Names, you may prefer setting them in Forms' ON-LOGON trigger with Dbms_Application_Info package's methods using this code :
Declare
v_db_name varchar2(35) := 'mydb1';
v_lg_name varchar2(350):= 'some DesiRed Value'; -- such as a username credential when the current user is being logged on to the DB OR SYS_CONTEXT('USERENV', 'IP_ADDRESS') provided static IP values are assigned per each user.
v_app_name varchar2(350):= :SYSTEM.CURRENT_FORM;
Begin
Logon(:Parameter.Un,:Parameter.Pwd||'#'||v_db_name); -- Un & Pwd are defined in Parameters node of Forms
Dbms_Application_Info.Set_Client_Info( v_lg_name );
Dbms_Application_Info.Set_Module( v_app_name, null );
End;
Whenever you need who logged your application, may issue this sql to see the related session information (provided your current session has select privilege to query gv$session dictionary view):
select s.*
from gv$session s
where lower(s.client_info) like lower('%'||'&cli_info'||'%')
and s.module = 'myApp'
order by floor(s.last_call_et / 60), s.username, s.logon_time desc
Sure; use "USER" system variable. For example:
message('You are connected as ' || user);
I'm currently working on an application in Oracle Application Express 5, more specifically I'm trying to create a custom authentication scheme.
I started by creating a function in the SQL command window that would provide my application with a basic level of authentication. I want my users to be able to sign in with their personal student reference number (srn) and date of birth (dob) and this information is taken from the table "student".
create or replace function validate_user_from_db
(p_username in number, p_password in date)
return boolean
as v_pw_check varchar2(1);
begin select 'x' into v_pw_check
from student
where upper(srn) = upper(p_username)
and dob = p_password; apex_util.set_authentication_result(0);
return true; exception when no_data_found then apex_util.set_authentication_result(4);
return false;
end validate_user_from_db;
This function compiled with no errors and so I then went on to create a simple query that would test the function.
declare
vresult varchar2(10);
begin
if validate_user_from_db ('30134852', '08/17/1997') then
DBMS_OUTPUT.PUT_LINE('Welcome Back');
else
DBMS_OUTPUT.PUT_LINE('Error');
end if;
end;
The query was successful and was outputting "Welcome Back" when the correct credentials were filled. Now that everything was working how I'd hoped I went about creating a new authentication scheme. I named it "User Validation" and set the scheme type to custom.
I've been following a tutorial and researching into authentication schemes and it was suggested that in the PL/SQL code I place the line,
return validate_user_from_db;
but when I saved and compiled it I got this error message.
Error Code
In attempt to try and resolve this issue I decided to write the following function in PL/SQL code window and it compiled without any issues, but when I try run the application and use correct login credentials it just hits me with an error message stating "Invalid Login Credentials".
function validate_user_from_db
(p_username in number, p_password in date)
return boolean
as v_pw_check varchar2(1);
begin select 'x' into v_pw_check
from student
where upper(srn) = upper(p_username)
and dob = p_password; apex_util.set_authentication_result(0);
return true; exception when no_data_found then apex_util.set_authentication_result(4);
return false;
end validate_user_from_db;
Any help will be much appreciated as this is my firs time creating authentication with Oracle Apex.
I resolved the issue after messing around with a test application. Turns out a login page is automatically generated depending on the authentication scheme you have set in place. Make sure you delete your existing login page when you change authentication.
I am attempting to send an email using a sql procedure, and am getting some errors. Here is my relevant code:
IF cur_email%FOUND THEN
stu_email := schema.get_person_email_adr(v_id);
IF send_email = 'Y' THEN
UTL_MAIL.SEND (sender => v_email_from, -- line of error
recipients => stu_email,
subject => v_email_subject,
mime_type => 'text/html',
message => v_email_body );
END IF;
END IF;
I will be getting multiple "v_id", and am trying to send an email to each one that I get, so I was also wondering if I am doing that correctly? The error that I am getting is this:
PLS-00201: identifier 'UTL_MAIL' must be declared
I am not sure why I am encountering this, Before I made some of these changes, I never received this error, so I believe that the utl_mail set up is not the problem.
Thanks!
UTL_MAIL is not installed by default, because it requires some configuring on the part of the sysadmin team. Find out more.
So, perhaps it has not been installed, or perhaps EXECUTE privilege on it has not been granted to your stored procedure owner.