Fictional phone numbers with pre-defined OTP for testing (Like in Firebase) #5358
|
Firebase allows you to create fictional phone numbers with a pre-defined OTP. This is very useful when running tests and App Store reviewers need a test account so they can get past authentication without using their personal phone number. More info on Firebase's functionality and its benefits here. I can't find any info whether Supabase or GoTrue support this functionality. Is there a possibility it might be implemented eventually or does anyone know of a different solution to this problem? EDIT: The solution I ended up using is a trigger function on -- This functions resets the confirmation token to a known value to enable logging in without receiving an SMS.
-- Use for developing, testing/cicd and app store reviewers.
CREATE FUNCTION test_credentials()
RETURNS TRIGGER
AS $$
BEGIN
IF (NEW.phone = ANY(array['<test-phone1>', '<test-phone2>'])) THEN
NEW.confirmation_token := '654321';
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER test_credentials BEFORE INSERT OR UPDATE ON auth.users FOR EACH ROW EXECUTE PROCEDURE test_credentials(); |
Replies: 9 comments 29 replies
|
Where you able to find a solution? |
|
@DriesCruyskens for for me too, with the |
|
One cool improvement I see so far would be to have a table in auth schema called like |
|
For anyone interested in making this work for email: #10298 (comment) |
|
If you're like me and ran into some issues with this cool approach: the phone is saved without the leading "+". Here's the complete working setup kudos to everybody in this discussion. -- This functions resets the confirmation token to a known value to enable logging in without receiving an SMS.
-- Use for developing, testing/cicd and app store reviewers.
CREATE FUNCTION test_credentials()
RETURNS TRIGGER
AS $$
BEGIN
IF (NEW.phone = ANY(array['41791111111', '41792222222'])) THEN
NEW.confirmation_token := '123456';
NEW.confirmation_sent_at := now();
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER test_credentials BEFORE INSERT OR UPDATE ON auth.users FOR EACH ROW EXECUTE PROCEDURE test_credentials(); |
|
This does not work for me. (I am using Twilio) ! |
|
I found a solution. @jordiup had the right idea: the token is now hashed. See also: https://github.com/supabase/gotrue/blob/7fbb0ad56bd01c3e603e495aa514ec4e3bf35c7a/internal/api/verify.go#L462 (code at time of writing) This adjusted trigger function worked for me. -- This functions resets the confirmation token to a known value to enable logging in without receiving an SMS.
-- Use for developing, testing/cicd and app store reviewers.
CREATE FUNCTION test_credentials()
RETURNS TRIGGER
AS $$
BEGIN
IF (NEW.phone = ANY(array['41791111111', '41792222222'])) THEN
NEW.confirmation_token := encode(sha224(concat(NEW.phone,'123456')::bytea), 'hex');
NEW.confirmation_sent_at := now();
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER test_credentials BEFORE INSERT OR UPDATE ON auth.users FOR EACH ROW EXECUTE PROCEDURE test_credentials(); |
|
This problem has now been resolved in the Supabase Dashboard, has'nt it ?
…On Fri, Dec 22, 2023 at 5:18 AM meraj759 ***@***.***> wrote:
-- This functions resets the confirmation token to a known value to enable
logging in without receiving an SMS.
-- Use for developing, testing/cicd and app store reviewers.
CREATE FUNCTION test_credentials()
RETURNS TRIGGER
AS $$
BEGIN
IF (NEW.phone = ANY(array['41791111111', '41792222222'])) THEN
NEW.confirmation_token := '123456';
NEW.confirmation_sent_at := now();
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER test_credentials BEFORE INSERT OR UPDATE ON auth.users FOR
EACH ROW EXECUTE PROCEDURE test_credentials();
—
Reply to this email directly, view it on GitHub
<#5358 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUYYUXREUTV3DT6ODFKUYGLYKUJZHAVCNFSM5NXKR5P2U5DIOJSWCZC7NNSXTOKENFZWG5LTONUW63SDN5WW2ZLOOQ5TOOJSGQ2DQOI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|


I just found this option in the Supabase dashboard. 🎉 (Auth -> Providers -> Phone)