pocketbase icon indicating copy to clipboard operation
pocketbase copied to clipboard

Opinionated auth system

Open amin-abaspour opened this issue 1 year ago • 2 comments

Hi. I feel your auth system is too opinionated. First, not everyone uses email—many people just use a phone number. Second, not everyone relies on passwords; some just get an SMS code every time they log in. My users don't sign in or sign up, there is no such distinction. I’m using a completely unknown SMS provider, and all I need from the auth system is a phone number. Nothing else.

It’s very confusing—how can I authWithPassword when I don't have email and don’t want to use password? I don’t want to rely on hacks like adding the phone number as email or using a dummy password. The system shouldn’t be this much opinionated.

If I’m missing something, please guide me—how can I achieve this with PocketBase?

amin-abaspour avatar Feb 08 '25 23:02 amin-abaspour

Hi, if you absolutely need to use SMS code, you can implement it yourself extending PocketBase. Check #350 for some clues (but keep in mind this is a 2022 comment and that you'll have to adjust it with your SMS provider API).

Otherwise, you should use something else.

About your feelings that "the system shouldn’t be this much opinionated." i quote the maintainer:

Please check the note at the beginning of the FAQ. Again, this is a personal and non-commercial open source software developed entirely on volunteer basis. It is a piece of code that I'm sharing with you and other interested users. It is up to you to decide whether you want to use or not [...]. The code is as it is without other promises.

chnfyi avatar Feb 09 '25 00:02 chnfyi

@ma-abaspour The currently supported authentication methods are listed in https://pocketbase.io/docs/authentication/.

Authentication with an SMS code is not supported out of the box because there is no standard for this and will vary from one provider to another. This has nothing to do with being "too opinionated".

With that said, neither the email, nor the email authentication are required.

You can mark the email field as optional by toggle off the "Nonempty" field option: email_field_screenshots

You can add a new "phone" text field to your auth collection and register a UNIQUE index for it from the "Unique constraints and indexes" collection fields section.

If you want SMS auth you'll have to implement it on your own by registering custom routes with Go or JavaScript (or alternatively modifying the OnRecordRequestOTPRequest/OnRecordAuthWithOTPRequest app event hooks).

Please spend some time reading the documentation and more specifically https://pocketbase.io/docs/use-as-framework/.

If you need further help, open a Q&A discussion and elaborate more on your use case (e.g. what provider do you use) and share the code sample that you've tried.

ganigeorgiev avatar Feb 09 '25 05:02 ganigeorgiev