Bỏ qua, đến nội dung

@digiforce-nc/plugin-auth-sms ​

Plugin xác thực qua SMS OTP — cho phép user đăng nhập bằng số điện thoại và mã xác minh gửi qua tin nhắn. Phụ thuộc vào plugin-verification để quản lý luồng gửi và xác minh OTP.

Plugin này làm gì? ​

SMSAuth kế thừa BaseAuth, triển khai xác thực OTP (One-Time Password) qua SMS. Không sử dụng OAuth hay redirect — thay vào đó, user nhập số điện thoại, nhận mã OTP qua SMS, rồi nhập mã để đăng nhập. Plugin chỉ hoạt động khi plugin-verification đã được cài đặt.

Đặc điểm chính ​

#Đặc điểmChi tiết
1OTP-basedKhông OAuth, không redirect — xác thực bằng mã OTP gửi qua SMS
2Peer dependencyYêu cầu plugin-verification — không tự gửi SMS
3Verification flowSử dụng verificationManager để request/verify OTP
4Phone-based lookupTìm local user theo số điện thoại
5Legacy migrationHỗ trợ migration từ smsAuthEnabled cũ sang authenticators mới

Luồng xác thực ​

Cấu hình ​

Tham sốKiểuMô tả
public.verifierstringTên verifier sử dụng (phải cấu hình trong plugin-verification)
public.autoSignupbooleanTự tạo tài khoản nếu user chưa tồn tại

Cấu hình phụ thuộc (plugin-verification) ​

SMS verifier cần được cấu hình riêng trong plugin-verification với provider cụ thể:

ProviderCấu hình cần thiết
TwilioaccountSid, authToken, from
Aliyun SMSaccessKeyId, accessKeySecret, signName, templateCode
Tencent SMSsecretId, secretKey, appId, signName, templateId

Database ​

Plugin sử dụng các bảng từ plugin-verification:

BảngMô tả
verifiersCấu hình verifier (tên, provider, thông số)
otpRecordsBản ghi OTP đã gửi (uuid, code, phone, expiresAt)
authenticatorsBản ghi authenticator (migration từ smsAuthEnabled)

API endpoints ​

EndpointQuyềnMô tả
auth:signInPublicĐăng nhập — gửi kèm authenticator, phone, uuid, code
verification:createPublicYêu cầu gửi OTP (thuộc plugin-verification)

Thành phần client ​

Thành phầnMô tả
SigninPageTrang đăng nhập SMS với VerificationForm (nhập SĐT → nhập OTP)
OptionsForm cấu hình SMS auth trong Settings, có VerifierSelect

Dependencies ​

PackageVai trò
@digiforce-nc/plugin-verificationQuản lý OTP: gửi SMS, lưu/verify mã (peer dependency)
@digiforce-nc/authBase auth framework (peer)
@digiforce-nc/serverServer framework (peer)
@digiforce-nc/clientClient framework (peer)

Mục lục chi tiết ​