@bagelink/auth 1.12.16 → 1.12.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +25 -3
- package/dist/index.cjs +101 -6
- package/dist/index.mjs +101 -6
- package/dist/types.d.ts +23 -1
- package/dist/useAuth.d.ts +11 -3
- package/package.json +1 -1
- package/src/api.ts +55 -6
- package/src/types.ts +32 -0
- package/src/useAuth.ts +112 -0
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RegisterRequest, UpdateAccountRequest, ChangePasswordRequest, ForgotPasswordRequest, ResetPasswordRequest, SendVerificationRequest, VerifyEmailRequest, AuthenticationAccount, PasswordLoginRequest, EmailTokenSendRequest, EmailTokenVerifyRequest, OTPSendRequest, OTPVerifyRequest, SSOLoginRequest, LoginResponse, RegisterResponse, LogoutResponse, GetMeResponse, UpdateMeResponse, DeleteMeResponse, ChangePasswordResponse, ForgotPasswordResponse, ResetPasswordResponse, VerifyResetTokenResponse, SendVerificationResponse, VerifyEmailResponse, RefreshSessionResponse, GetSessionsResponse, DeleteSessionResponse, DeleteAllSessionsResponse, CleanupSessionsResponse, GetMethodsResponse, GetAuthStatusResponse, SendEmailTokenResponse, VerifyEmailTokenResponse, SendOTPResponse, VerifyOTPResponse, LegacySSOLoginResponse, SSOProvider, SSOInitiateRequest, SSOCallbackRequest, SSOLinkRequest, InitiateSSOResponse, CallbackSSOResponse, LinkSSOResponse, UnlinkSSOResponse, GetTenantsResponse, GetTenantResponse, CreateTenantResponse, UpdateTenantResponse, DeleteTenantResponse, GetTenantMembersResponse, AddTenantMemberResponse, UpdateTenantMemberResponse, DeleteTenantMemberResponse, GetTenantRolesResponse, CreateInvitationResponse, GetInvitationResponse, AcceptInvitationResponse, CreateTenantRequest, UpdateTenantRequest, AddMemberRequest, UpdateMemberRequest, CreateInvitationRequest, AcceptInvitationRequest } from './types';
|
|
1
|
+
import { RegisterRequest, UpdateAccountRequest, ChangePasswordRequest, ForgotPasswordRequest, ResetPasswordRequest, SendVerificationRequest, VerifyEmailRequest, AuthenticationAccount, PasswordLoginRequest, EmailTokenSendRequest, EmailTokenVerifyRequest, OTPSendRequest, OTPVerifyRequest, SMSSendRequest, SMSVerifyRequest, GenerateTokenRequest, RedeemTokenRequest, SSOLoginRequest, LoginResponse, RegisterResponse, LogoutResponse, GetMeResponse, UpdateMeResponse, DeleteMeResponse, ChangePasswordResponse, ForgotPasswordResponse, ResetPasswordResponse, VerifyResetTokenResponse, SendVerificationResponse, VerifyEmailResponse, RefreshSessionResponse, GetSessionsResponse, DeleteSessionResponse, DeleteAllSessionsResponse, CleanupSessionsResponse, GetMethodsResponse, GetAuthStatusResponse, SendEmailTokenResponse, VerifyEmailTokenResponse, SendOTPResponse, VerifyOTPResponse, SendSMSResponse, VerifySMSResponse, GenerateLoginTokenResponse, RedeemLoginTokenResponse, LegacySSOLoginResponse, SSOProvider, SSOInitiateRequest, SSOCallbackRequest, SSOLinkRequest, InitiateSSOResponse, CallbackSSOResponse, LinkSSOResponse, UnlinkSSOResponse, GetTenantsResponse, GetTenantResponse, CreateTenantResponse, UpdateTenantResponse, DeleteTenantResponse, GetTenantMembersResponse, AddTenantMemberResponse, UpdateTenantMemberResponse, DeleteTenantMemberResponse, GetTenantRolesResponse, CreateInvitationResponse, GetInvitationResponse, AcceptInvitationResponse, CreateTenantRequest, UpdateTenantRequest, AddMemberRequest, UpdateMemberRequest, CreateInvitationRequest, AcceptInvitationRequest } from './types';
|
|
2
2
|
export declare class AuthApi {
|
|
3
3
|
private api;
|
|
4
4
|
private currentTenantId;
|
|
@@ -37,13 +37,35 @@ export declare class AuthApi {
|
|
|
37
37
|
*/
|
|
38
38
|
verifyEmailToken(data: EmailTokenVerifyRequest): Promise<VerifyEmailTokenResponse>;
|
|
39
39
|
/**
|
|
40
|
-
* Send
|
|
40
|
+
* Send SMS verification code to phone number
|
|
41
|
+
*/
|
|
42
|
+
sendSMS(data: SMSSendRequest): Promise<SendSMSResponse>;
|
|
43
|
+
/**
|
|
44
|
+
* Verify SMS code and login
|
|
45
|
+
*/
|
|
46
|
+
verifySMS(data: SMSVerifyRequest): Promise<VerifySMSResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated Use sendSMS() instead
|
|
41
49
|
*/
|
|
42
50
|
sendOTP(data: OTPSendRequest): Promise<SendOTPResponse>;
|
|
43
51
|
/**
|
|
44
|
-
*
|
|
52
|
+
* @deprecated Use verifySMS() instead
|
|
45
53
|
*/
|
|
46
54
|
verifyOTP(data: OTPVerifyRequest): Promise<VerifyOTPResponse>;
|
|
55
|
+
/**
|
|
56
|
+
* Generate a one-time login token.
|
|
57
|
+
* Omit target_identity_id to generate for yourself (e.g. desktop → mobile).
|
|
58
|
+
* Provide target_identity_id to generate for another user (admin only).
|
|
59
|
+
*/
|
|
60
|
+
generateLoginToken(data?: GenerateTokenRequest): Promise<GenerateLoginTokenResponse>;
|
|
61
|
+
/**
|
|
62
|
+
* Redeem a one-time login token (no authentication required).
|
|
63
|
+
*/
|
|
64
|
+
redeemLoginToken(data: RedeemTokenRequest): Promise<RedeemLoginTokenResponse>;
|
|
65
|
+
/**
|
|
66
|
+
* Check if a login token is still valid (no auth required).
|
|
67
|
+
*/
|
|
68
|
+
getLoginTokenStatus(token: string): Promise<any>;
|
|
47
69
|
/**
|
|
48
70
|
* Login with SSO provider (legacy endpoint without PKCE)
|
|
49
71
|
*/
|
package/dist/index.cjs
CHANGED
|
@@ -129,25 +129,60 @@ class AuthApi {
|
|
|
129
129
|
* Send email token to user
|
|
130
130
|
*/
|
|
131
131
|
async sendEmailToken(data) {
|
|
132
|
-
return this.api.post("authentication/login/email
|
|
132
|
+
return this.api.post("authentication/login/email/send", data);
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
135
135
|
* Verify email token and login
|
|
136
136
|
*/
|
|
137
137
|
async verifyEmailToken(data) {
|
|
138
|
-
return this.api.post("authentication/login/email
|
|
138
|
+
return this.api.post("authentication/login/email/verify", data);
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
* Send
|
|
141
|
+
* Send SMS verification code to phone number
|
|
142
|
+
*/
|
|
143
|
+
async sendSMS(data) {
|
|
144
|
+
return this.api.post("authentication/login/sms/send", data);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Verify SMS code and login
|
|
148
|
+
*/
|
|
149
|
+
async verifySMS(data) {
|
|
150
|
+
return this.api.post("authentication/login/sms/verify", data);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @deprecated Use sendSMS() instead
|
|
142
154
|
*/
|
|
143
155
|
async sendOTP(data) {
|
|
144
|
-
return this.
|
|
156
|
+
return this.sendSMS(data);
|
|
145
157
|
}
|
|
146
158
|
/**
|
|
147
|
-
*
|
|
159
|
+
* @deprecated Use verifySMS() instead
|
|
148
160
|
*/
|
|
149
161
|
async verifyOTP(data) {
|
|
150
|
-
return this.
|
|
162
|
+
return this.verifySMS(data);
|
|
163
|
+
}
|
|
164
|
+
// ============================================
|
|
165
|
+
// Login Token Methods
|
|
166
|
+
// ============================================
|
|
167
|
+
/**
|
|
168
|
+
* Generate a one-time login token.
|
|
169
|
+
* Omit target_identity_id to generate for yourself (e.g. desktop → mobile).
|
|
170
|
+
* Provide target_identity_id to generate for another user (admin only).
|
|
171
|
+
*/
|
|
172
|
+
async generateLoginToken(data = {}) {
|
|
173
|
+
return this.api.post("authentication/login-token/generate", data);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Redeem a one-time login token (no authentication required).
|
|
177
|
+
*/
|
|
178
|
+
async redeemLoginToken(data) {
|
|
179
|
+
return this.api.post("authentication/login-token/redeem", data);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Check if a login token is still valid (no auth required).
|
|
183
|
+
*/
|
|
184
|
+
async getLoginTokenStatus(token) {
|
|
185
|
+
return this.api.get(`authentication/login-token/${token}/status`);
|
|
151
186
|
}
|
|
152
187
|
/**
|
|
153
188
|
* Login with SSO provider (legacy endpoint without PKCE)
|
|
@@ -1151,6 +1186,54 @@ function useAuth() {
|
|
|
1151
1186
|
emitter.emit(AuthState.LOGIN);
|
|
1152
1187
|
return data;
|
|
1153
1188
|
}
|
|
1189
|
+
async function sendSMS(data) {
|
|
1190
|
+
const { data: response } = await api.sendSMS(data);
|
|
1191
|
+
return response;
|
|
1192
|
+
}
|
|
1193
|
+
async function verifySMS(data) {
|
|
1194
|
+
const { data: response } = await api.verifySMS(data);
|
|
1195
|
+
if (response.success === true && response.requires_verification !== true) {
|
|
1196
|
+
await checkAuth();
|
|
1197
|
+
}
|
|
1198
|
+
emitter.emit(AuthState.LOGIN);
|
|
1199
|
+
return response;
|
|
1200
|
+
}
|
|
1201
|
+
async function sendOTP(data) {
|
|
1202
|
+
return sendSMS(data);
|
|
1203
|
+
}
|
|
1204
|
+
async function verifyOTP(data) {
|
|
1205
|
+
return verifySMS(data);
|
|
1206
|
+
}
|
|
1207
|
+
async function sendEmailToken(data) {
|
|
1208
|
+
const { data: response } = await api.sendEmailToken(data);
|
|
1209
|
+
return response;
|
|
1210
|
+
}
|
|
1211
|
+
async function verifyEmailToken(data) {
|
|
1212
|
+
const { data: response } = await api.verifyEmailToken(data);
|
|
1213
|
+
if (response.success === true && response.requires_verification !== true) {
|
|
1214
|
+
await checkAuth();
|
|
1215
|
+
}
|
|
1216
|
+
emitter.emit(AuthState.LOGIN);
|
|
1217
|
+
return response;
|
|
1218
|
+
}
|
|
1219
|
+
async function generateLoginToken(data = {}) {
|
|
1220
|
+
const { data: response } = await api.generateLoginToken(data);
|
|
1221
|
+
return response;
|
|
1222
|
+
}
|
|
1223
|
+
async function loginWithToken(token) {
|
|
1224
|
+
try {
|
|
1225
|
+
const { data: response } = await api.redeemLoginToken({ token });
|
|
1226
|
+
if (response.success === true && response.requires_verification !== true) {
|
|
1227
|
+
await checkAuth();
|
|
1228
|
+
}
|
|
1229
|
+
if (response.success) {
|
|
1230
|
+
emitter.emit(AuthState.LOGIN);
|
|
1231
|
+
}
|
|
1232
|
+
return response.success === true;
|
|
1233
|
+
} catch {
|
|
1234
|
+
return false;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1154
1237
|
async function checkAuth() {
|
|
1155
1238
|
try {
|
|
1156
1239
|
const { data } = await api.getCurrentUser();
|
|
@@ -1377,6 +1460,18 @@ function useAuth() {
|
|
|
1377
1460
|
signup,
|
|
1378
1461
|
checkAuth,
|
|
1379
1462
|
refreshSession,
|
|
1463
|
+
// SMS Login
|
|
1464
|
+
sendSMS,
|
|
1465
|
+
verifySMS,
|
|
1466
|
+
// SMS Login (deprecated aliases)
|
|
1467
|
+
sendOTP,
|
|
1468
|
+
verifyOTP,
|
|
1469
|
+
// Email Token Login
|
|
1470
|
+
sendEmailToken,
|
|
1471
|
+
verifyEmailToken,
|
|
1472
|
+
// Login Token (one-time token auth)
|
|
1473
|
+
generateLoginToken,
|
|
1474
|
+
loginWithToken,
|
|
1380
1475
|
// SSO Authentication (lower-level - prefer using sso.google.redirect())
|
|
1381
1476
|
initiateSSO,
|
|
1382
1477
|
loginWithSSO,
|
package/dist/index.mjs
CHANGED
|
@@ -127,25 +127,60 @@ class AuthApi {
|
|
|
127
127
|
* Send email token to user
|
|
128
128
|
*/
|
|
129
129
|
async sendEmailToken(data) {
|
|
130
|
-
return this.api.post("authentication/login/email
|
|
130
|
+
return this.api.post("authentication/login/email/send", data);
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
133
|
* Verify email token and login
|
|
134
134
|
*/
|
|
135
135
|
async verifyEmailToken(data) {
|
|
136
|
-
return this.api.post("authentication/login/email
|
|
136
|
+
return this.api.post("authentication/login/email/verify", data);
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
|
-
* Send
|
|
139
|
+
* Send SMS verification code to phone number
|
|
140
|
+
*/
|
|
141
|
+
async sendSMS(data) {
|
|
142
|
+
return this.api.post("authentication/login/sms/send", data);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Verify SMS code and login
|
|
146
|
+
*/
|
|
147
|
+
async verifySMS(data) {
|
|
148
|
+
return this.api.post("authentication/login/sms/verify", data);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @deprecated Use sendSMS() instead
|
|
140
152
|
*/
|
|
141
153
|
async sendOTP(data) {
|
|
142
|
-
return this.
|
|
154
|
+
return this.sendSMS(data);
|
|
143
155
|
}
|
|
144
156
|
/**
|
|
145
|
-
*
|
|
157
|
+
* @deprecated Use verifySMS() instead
|
|
146
158
|
*/
|
|
147
159
|
async verifyOTP(data) {
|
|
148
|
-
return this.
|
|
160
|
+
return this.verifySMS(data);
|
|
161
|
+
}
|
|
162
|
+
// ============================================
|
|
163
|
+
// Login Token Methods
|
|
164
|
+
// ============================================
|
|
165
|
+
/**
|
|
166
|
+
* Generate a one-time login token.
|
|
167
|
+
* Omit target_identity_id to generate for yourself (e.g. desktop → mobile).
|
|
168
|
+
* Provide target_identity_id to generate for another user (admin only).
|
|
169
|
+
*/
|
|
170
|
+
async generateLoginToken(data = {}) {
|
|
171
|
+
return this.api.post("authentication/login-token/generate", data);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Redeem a one-time login token (no authentication required).
|
|
175
|
+
*/
|
|
176
|
+
async redeemLoginToken(data) {
|
|
177
|
+
return this.api.post("authentication/login-token/redeem", data);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Check if a login token is still valid (no auth required).
|
|
181
|
+
*/
|
|
182
|
+
async getLoginTokenStatus(token) {
|
|
183
|
+
return this.api.get(`authentication/login-token/${token}/status`);
|
|
149
184
|
}
|
|
150
185
|
/**
|
|
151
186
|
* Login with SSO provider (legacy endpoint without PKCE)
|
|
@@ -1149,6 +1184,54 @@ function useAuth() {
|
|
|
1149
1184
|
emitter.emit(AuthState.LOGIN);
|
|
1150
1185
|
return data;
|
|
1151
1186
|
}
|
|
1187
|
+
async function sendSMS(data) {
|
|
1188
|
+
const { data: response } = await api.sendSMS(data);
|
|
1189
|
+
return response;
|
|
1190
|
+
}
|
|
1191
|
+
async function verifySMS(data) {
|
|
1192
|
+
const { data: response } = await api.verifySMS(data);
|
|
1193
|
+
if (response.success === true && response.requires_verification !== true) {
|
|
1194
|
+
await checkAuth();
|
|
1195
|
+
}
|
|
1196
|
+
emitter.emit(AuthState.LOGIN);
|
|
1197
|
+
return response;
|
|
1198
|
+
}
|
|
1199
|
+
async function sendOTP(data) {
|
|
1200
|
+
return sendSMS(data);
|
|
1201
|
+
}
|
|
1202
|
+
async function verifyOTP(data) {
|
|
1203
|
+
return verifySMS(data);
|
|
1204
|
+
}
|
|
1205
|
+
async function sendEmailToken(data) {
|
|
1206
|
+
const { data: response } = await api.sendEmailToken(data);
|
|
1207
|
+
return response;
|
|
1208
|
+
}
|
|
1209
|
+
async function verifyEmailToken(data) {
|
|
1210
|
+
const { data: response } = await api.verifyEmailToken(data);
|
|
1211
|
+
if (response.success === true && response.requires_verification !== true) {
|
|
1212
|
+
await checkAuth();
|
|
1213
|
+
}
|
|
1214
|
+
emitter.emit(AuthState.LOGIN);
|
|
1215
|
+
return response;
|
|
1216
|
+
}
|
|
1217
|
+
async function generateLoginToken(data = {}) {
|
|
1218
|
+
const { data: response } = await api.generateLoginToken(data);
|
|
1219
|
+
return response;
|
|
1220
|
+
}
|
|
1221
|
+
async function loginWithToken(token) {
|
|
1222
|
+
try {
|
|
1223
|
+
const { data: response } = await api.redeemLoginToken({ token });
|
|
1224
|
+
if (response.success === true && response.requires_verification !== true) {
|
|
1225
|
+
await checkAuth();
|
|
1226
|
+
}
|
|
1227
|
+
if (response.success) {
|
|
1228
|
+
emitter.emit(AuthState.LOGIN);
|
|
1229
|
+
}
|
|
1230
|
+
return response.success === true;
|
|
1231
|
+
} catch {
|
|
1232
|
+
return false;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1152
1235
|
async function checkAuth() {
|
|
1153
1236
|
try {
|
|
1154
1237
|
const { data } = await api.getCurrentUser();
|
|
@@ -1375,6 +1458,18 @@ function useAuth() {
|
|
|
1375
1458
|
signup,
|
|
1376
1459
|
checkAuth,
|
|
1377
1460
|
refreshSession,
|
|
1461
|
+
// SMS Login
|
|
1462
|
+
sendSMS,
|
|
1463
|
+
verifySMS,
|
|
1464
|
+
// SMS Login (deprecated aliases)
|
|
1465
|
+
sendOTP,
|
|
1466
|
+
verifyOTP,
|
|
1467
|
+
// Email Token Login
|
|
1468
|
+
sendEmailToken,
|
|
1469
|
+
verifyEmailToken,
|
|
1470
|
+
// Login Token (one-time token auth)
|
|
1471
|
+
generateLoginToken,
|
|
1472
|
+
loginWithToken,
|
|
1378
1473
|
// SSO Authentication (lower-level - prefer using sso.google.redirect())
|
|
1379
1474
|
initiateSSO,
|
|
1380
1475
|
loginWithSSO,
|
package/dist/types.d.ts
CHANGED
|
@@ -104,7 +104,7 @@ export type GetInvitationResponse = AxiosResponse<{
|
|
|
104
104
|
last_name?: string | null;
|
|
105
105
|
}>;
|
|
106
106
|
export type AcceptInvitationResponse = AxiosResponse<MessageResponse>;
|
|
107
|
-
export type AuthenticationMethodType = 'password' | 'email_token' | 'sso' | 'otp';
|
|
107
|
+
export type AuthenticationMethodType = 'password' | 'email_token' | 'email' | 'sso' | 'otp' | 'sms' | 'login_token';
|
|
108
108
|
export type SSOProvider = 'google' | 'microsoft' | 'github' | 'okta' | 'apple' | 'facebook' | 'custom';
|
|
109
109
|
export interface AuthenticationAccount {
|
|
110
110
|
created_at?: string;
|
|
@@ -244,6 +244,24 @@ export interface OTPVerifyRequest {
|
|
|
244
244
|
verification_hash: string;
|
|
245
245
|
timestamp: number;
|
|
246
246
|
}
|
|
247
|
+
/** @alias OTPSendRequest — renamed to SMSSendRequest in API v2 */
|
|
248
|
+
export type SMSSendRequest = OTPSendRequest;
|
|
249
|
+
/** @alias OTPVerifyRequest — renamed to SMSVerifyRequest in API v2 */
|
|
250
|
+
export type SMSVerifyRequest = OTPVerifyRequest;
|
|
251
|
+
export interface GenerateTokenRequest {
|
|
252
|
+
target_identity_id?: string;
|
|
253
|
+
expires_in_minutes?: number;
|
|
254
|
+
}
|
|
255
|
+
export interface GenerateTokenResponse {
|
|
256
|
+
token: string;
|
|
257
|
+
target_identity_id: string;
|
|
258
|
+
issued_by: string;
|
|
259
|
+
expires_at: string;
|
|
260
|
+
expires_in_minutes: number;
|
|
261
|
+
}
|
|
262
|
+
export interface RedeemTokenRequest {
|
|
263
|
+
token: string;
|
|
264
|
+
}
|
|
247
265
|
export interface SSOLoginRequest {
|
|
248
266
|
provider: SSOProvider;
|
|
249
267
|
authorization_code?: string;
|
|
@@ -371,6 +389,10 @@ export type SendEmailTokenResponse = AxiosResponse<AuthenticationResponse>;
|
|
|
371
389
|
export type VerifyEmailTokenResponse = AxiosResponse<AuthenticationResponse>;
|
|
372
390
|
export type SendOTPResponse = AxiosResponse<AuthenticationResponse>;
|
|
373
391
|
export type VerifyOTPResponse = AxiosResponse<AuthenticationResponse>;
|
|
392
|
+
export type SendSMSResponse = AxiosResponse<AuthenticationResponse>;
|
|
393
|
+
export type VerifySMSResponse = AxiosResponse<AuthenticationResponse>;
|
|
394
|
+
export type GenerateLoginTokenResponse = AxiosResponse<GenerateTokenResponse>;
|
|
395
|
+
export type RedeemLoginTokenResponse = AxiosResponse<AuthenticationResponse>;
|
|
374
396
|
export type LegacySSOLoginResponse = AxiosResponse<AuthenticationResponse>;
|
|
375
397
|
/**
|
|
376
398
|
* Extract unified user from account info
|
package/dist/useAuth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { App, ObjectPlugin } from 'vue';
|
|
2
|
-
import { AccountInfo, User, NewUser, UpdatePasswordForm, UpdateAccountRequest, AuthEventMap, SSOProvider, SSOInitiateRequest, SSOCallbackRequest, SSOLinkRequest, TenantInfo, CreateTenantRequest, UpdateTenantRequest, AddMemberRequest, UpdateMemberRequest, CreateInvitationRequest, AcceptInvitationRequest, AuthState } from './types';
|
|
2
|
+
import { AccountInfo, User, NewUser, UpdatePasswordForm, UpdateAccountRequest, AuthEventMap, SSOProvider, SSOInitiateRequest, SSOCallbackRequest, SSOLinkRequest, TenantInfo, CreateTenantRequest, UpdateTenantRequest, AddMemberRequest, UpdateMemberRequest, CreateInvitationRequest, AcceptInvitationRequest, OTPSendRequest, OTPVerifyRequest, SMSSendRequest, SMSVerifyRequest, EmailTokenSendRequest, EmailTokenVerifyRequest, GenerateTokenRequest, GenerateTokenResponse, AuthenticationResponse, AuthState } from './types';
|
|
3
3
|
import { RedirectConfig, NormalizedRedirectConfig } from './types/redirect';
|
|
4
4
|
interface InitParams {
|
|
5
5
|
baseURL: string;
|
|
@@ -171,11 +171,19 @@ export declare function useAuth(): {
|
|
|
171
171
|
login: (credentials: {
|
|
172
172
|
email: string;
|
|
173
173
|
password: string;
|
|
174
|
-
}) => Promise<
|
|
174
|
+
}) => Promise<AuthenticationResponse>;
|
|
175
175
|
logout: () => Promise<void>;
|
|
176
|
-
signup: (newUser: NewUser) => Promise<
|
|
176
|
+
signup: (newUser: NewUser) => Promise<AuthenticationResponse>;
|
|
177
177
|
checkAuth: () => Promise<boolean>;
|
|
178
178
|
refreshSession: () => Promise<void>;
|
|
179
|
+
sendSMS: (data: SMSSendRequest) => Promise<AuthenticationResponse>;
|
|
180
|
+
verifySMS: (data: SMSVerifyRequest) => Promise<AuthenticationResponse>;
|
|
181
|
+
sendOTP: (data: OTPSendRequest) => Promise<AuthenticationResponse>;
|
|
182
|
+
verifyOTP: (data: OTPVerifyRequest) => Promise<AuthenticationResponse>;
|
|
183
|
+
sendEmailToken: (data: EmailTokenSendRequest) => Promise<AuthenticationResponse>;
|
|
184
|
+
verifyEmailToken: (data: EmailTokenVerifyRequest) => Promise<AuthenticationResponse>;
|
|
185
|
+
generateLoginToken: (data?: GenerateTokenRequest) => Promise<GenerateTokenResponse>;
|
|
186
|
+
loginWithToken: (token: string) => Promise<boolean>;
|
|
179
187
|
initiateSSO: (provider: SSOProvider, params: SSOInitiateRequest) => Promise<string>;
|
|
180
188
|
loginWithSSO: (provider: SSOProvider, params: SSOCallbackRequest) => Promise<import('./types').SSOCallbackResponse>;
|
|
181
189
|
linkSSOProvider: (provider: SSOProvider, params: SSOLinkRequest) => Promise<void>;
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -13,6 +13,10 @@ import type {
|
|
|
13
13
|
EmailTokenVerifyRequest,
|
|
14
14
|
OTPSendRequest,
|
|
15
15
|
OTPVerifyRequest,
|
|
16
|
+
SMSSendRequest,
|
|
17
|
+
SMSVerifyRequest,
|
|
18
|
+
GenerateTokenRequest,
|
|
19
|
+
RedeemTokenRequest,
|
|
16
20
|
SSOLoginRequest,
|
|
17
21
|
LoginResponse,
|
|
18
22
|
RegisterResponse,
|
|
@@ -37,6 +41,10 @@ import type {
|
|
|
37
41
|
VerifyEmailTokenResponse,
|
|
38
42
|
SendOTPResponse,
|
|
39
43
|
VerifyOTPResponse,
|
|
44
|
+
SendSMSResponse,
|
|
45
|
+
VerifySMSResponse,
|
|
46
|
+
GenerateLoginTokenResponse,
|
|
47
|
+
RedeemLoginTokenResponse,
|
|
40
48
|
LegacySSOLoginResponse,
|
|
41
49
|
SSOProvider,
|
|
42
50
|
SSOInitiateRequest,
|
|
@@ -151,28 +159,69 @@ export class AuthApi {
|
|
|
151
159
|
* Send email token to user
|
|
152
160
|
*/
|
|
153
161
|
async sendEmailToken(data: EmailTokenSendRequest): Promise<SendEmailTokenResponse> {
|
|
154
|
-
return this.api.post('authentication/login/email
|
|
162
|
+
return this.api.post('authentication/login/email/send', data)
|
|
155
163
|
}
|
|
156
164
|
|
|
157
165
|
/**
|
|
158
166
|
* Verify email token and login
|
|
159
167
|
*/
|
|
160
168
|
async verifyEmailToken(data: EmailTokenVerifyRequest): Promise<VerifyEmailTokenResponse> {
|
|
161
|
-
return this.api.post('authentication/login/email
|
|
169
|
+
return this.api.post('authentication/login/email/verify', data)
|
|
162
170
|
}
|
|
163
171
|
|
|
164
172
|
/**
|
|
165
|
-
* Send
|
|
173
|
+
* Send SMS verification code to phone number
|
|
174
|
+
*/
|
|
175
|
+
async sendSMS(data: SMSSendRequest): Promise<SendSMSResponse> {
|
|
176
|
+
return this.api.post('authentication/login/sms/send', data)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Verify SMS code and login
|
|
181
|
+
*/
|
|
182
|
+
async verifySMS(data: SMSVerifyRequest): Promise<VerifySMSResponse> {
|
|
183
|
+
return this.api.post('authentication/login/sms/verify', data)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @deprecated Use sendSMS() instead
|
|
166
188
|
*/
|
|
167
189
|
async sendOTP(data: OTPSendRequest): Promise<SendOTPResponse> {
|
|
168
|
-
return this.
|
|
190
|
+
return this.sendSMS(data)
|
|
169
191
|
}
|
|
170
192
|
|
|
171
193
|
/**
|
|
172
|
-
*
|
|
194
|
+
* @deprecated Use verifySMS() instead
|
|
173
195
|
*/
|
|
174
196
|
async verifyOTP(data: OTPVerifyRequest): Promise<VerifyOTPResponse> {
|
|
175
|
-
return this.
|
|
197
|
+
return this.verifySMS(data)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ============================================
|
|
201
|
+
// Login Token Methods
|
|
202
|
+
// ============================================
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Generate a one-time login token.
|
|
206
|
+
* Omit target_identity_id to generate for yourself (e.g. desktop → mobile).
|
|
207
|
+
* Provide target_identity_id to generate for another user (admin only).
|
|
208
|
+
*/
|
|
209
|
+
async generateLoginToken(data: GenerateTokenRequest = {}): Promise<GenerateLoginTokenResponse> {
|
|
210
|
+
return this.api.post('authentication/login-token/generate', data)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Redeem a one-time login token (no authentication required).
|
|
215
|
+
*/
|
|
216
|
+
async redeemLoginToken(data: RedeemTokenRequest): Promise<RedeemLoginTokenResponse> {
|
|
217
|
+
return this.api.post('authentication/login-token/redeem', data)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Check if a login token is still valid (no auth required).
|
|
222
|
+
*/
|
|
223
|
+
async getLoginTokenStatus(token: string): Promise<any> {
|
|
224
|
+
return this.api.get(`authentication/login-token/${token}/status`)
|
|
176
225
|
}
|
|
177
226
|
|
|
178
227
|
/**
|
package/src/types.ts
CHANGED
|
@@ -140,8 +140,11 @@ export type AcceptInvitationResponse = AxiosResponse<MessageResponse>
|
|
|
140
140
|
export type AuthenticationMethodType
|
|
141
141
|
= | 'password'
|
|
142
142
|
| 'email_token'
|
|
143
|
+
| 'email'
|
|
143
144
|
| 'sso'
|
|
144
145
|
| 'otp'
|
|
146
|
+
| 'sms'
|
|
147
|
+
| 'login_token'
|
|
145
148
|
|
|
146
149
|
export type SSOProvider = 'google' | 'microsoft' | 'github' | 'okta' | 'apple' | 'facebook' | 'custom'
|
|
147
150
|
|
|
@@ -312,6 +315,31 @@ export interface OTPVerifyRequest {
|
|
|
312
315
|
timestamp: number
|
|
313
316
|
}
|
|
314
317
|
|
|
318
|
+
/** @alias OTPSendRequest — renamed to SMSSendRequest in API v2 */
|
|
319
|
+
export type SMSSendRequest = OTPSendRequest
|
|
320
|
+
|
|
321
|
+
/** @alias OTPVerifyRequest — renamed to SMSVerifyRequest in API v2 */
|
|
322
|
+
export type SMSVerifyRequest = OTPVerifyRequest
|
|
323
|
+
|
|
324
|
+
// ─── Login Token Types ────────────────────────────────────────────────────────
|
|
325
|
+
|
|
326
|
+
export interface GenerateTokenRequest {
|
|
327
|
+
target_identity_id?: string
|
|
328
|
+
expires_in_minutes?: number
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export interface GenerateTokenResponse {
|
|
332
|
+
token: string
|
|
333
|
+
target_identity_id: string
|
|
334
|
+
issued_by: string
|
|
335
|
+
expires_at: string
|
|
336
|
+
expires_in_minutes: number
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export interface RedeemTokenRequest {
|
|
340
|
+
token: string
|
|
341
|
+
}
|
|
342
|
+
|
|
315
343
|
export interface SSOLoginRequest {
|
|
316
344
|
provider: SSOProvider
|
|
317
345
|
authorization_code?: string
|
|
@@ -449,6 +477,10 @@ export type SendEmailTokenResponse = AxiosResponse<AuthenticationResponse>
|
|
|
449
477
|
export type VerifyEmailTokenResponse = AxiosResponse<AuthenticationResponse>
|
|
450
478
|
export type SendOTPResponse = AxiosResponse<AuthenticationResponse>
|
|
451
479
|
export type VerifyOTPResponse = AxiosResponse<AuthenticationResponse>
|
|
480
|
+
export type SendSMSResponse = AxiosResponse<AuthenticationResponse>
|
|
481
|
+
export type VerifySMSResponse = AxiosResponse<AuthenticationResponse>
|
|
482
|
+
export type GenerateLoginTokenResponse = AxiosResponse<GenerateTokenResponse>
|
|
483
|
+
export type RedeemLoginTokenResponse = AxiosResponse<AuthenticationResponse>
|
|
452
484
|
export type LegacySSOLoginResponse = AxiosResponse<AuthenticationResponse>
|
|
453
485
|
|
|
454
486
|
// ============================================
|
package/src/useAuth.ts
CHANGED
|
@@ -17,6 +17,15 @@ import type {
|
|
|
17
17
|
UpdateMemberRequest,
|
|
18
18
|
CreateInvitationRequest,
|
|
19
19
|
AcceptInvitationRequest,
|
|
20
|
+
OTPSendRequest,
|
|
21
|
+
OTPVerifyRequest,
|
|
22
|
+
SMSSendRequest,
|
|
23
|
+
SMSVerifyRequest,
|
|
24
|
+
EmailTokenSendRequest,
|
|
25
|
+
EmailTokenVerifyRequest,
|
|
26
|
+
GenerateTokenRequest,
|
|
27
|
+
GenerateTokenResponse,
|
|
28
|
+
AuthenticationResponse,
|
|
20
29
|
} from './types'
|
|
21
30
|
import type { RedirectConfig, NormalizedRedirectConfig } from './types/redirect'
|
|
22
31
|
import { ref, computed } from 'vue'
|
|
@@ -318,6 +327,93 @@ export function useAuth() {
|
|
|
318
327
|
return data
|
|
319
328
|
}
|
|
320
329
|
|
|
330
|
+
// ============================================
|
|
331
|
+
// SMS Login
|
|
332
|
+
// ============================================
|
|
333
|
+
|
|
334
|
+
async function sendSMS(data: SMSSendRequest): Promise<AuthenticationResponse> {
|
|
335
|
+
const { data: response } = await api.sendSMS(data)
|
|
336
|
+
return response
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async function verifySMS(data: SMSVerifyRequest): Promise<AuthenticationResponse> {
|
|
340
|
+
const { data: response } = await api.verifySMS(data)
|
|
341
|
+
|
|
342
|
+
if (response.success === true && response.requires_verification !== true) {
|
|
343
|
+
await checkAuth()
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
emitter.emit(AuthState.LOGIN)
|
|
347
|
+
return response
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** @deprecated Use sendSMS() instead */
|
|
351
|
+
async function sendOTP(data: OTPSendRequest): Promise<AuthenticationResponse> {
|
|
352
|
+
return sendSMS(data)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** @deprecated Use verifySMS() instead */
|
|
356
|
+
async function verifyOTP(data: OTPVerifyRequest): Promise<AuthenticationResponse> {
|
|
357
|
+
return verifySMS(data)
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// ============================================
|
|
361
|
+
// Email Token Login
|
|
362
|
+
// ============================================
|
|
363
|
+
|
|
364
|
+
async function sendEmailToken(data: EmailTokenSendRequest): Promise<AuthenticationResponse> {
|
|
365
|
+
const { data: response } = await api.sendEmailToken(data)
|
|
366
|
+
return response
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async function verifyEmailToken(data: EmailTokenVerifyRequest): Promise<AuthenticationResponse> {
|
|
370
|
+
const { data: response } = await api.verifyEmailToken(data)
|
|
371
|
+
|
|
372
|
+
if (response.success === true && response.requires_verification !== true) {
|
|
373
|
+
await checkAuth()
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
emitter.emit(AuthState.LOGIN)
|
|
377
|
+
return response
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// ============================================
|
|
381
|
+
// Login Token (one-time token auth)
|
|
382
|
+
// ============================================
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Generate a one-time login token.
|
|
386
|
+
* Omit target_identity_id to generate for yourself (e.g. desktop → mobile).
|
|
387
|
+
* Provide target_identity_id to generate for another user (admin only).
|
|
388
|
+
*/
|
|
389
|
+
async function generateLoginToken(data: GenerateTokenRequest = {}): Promise<GenerateTokenResponse> {
|
|
390
|
+
const { data: response } = await api.generateLoginToken(data)
|
|
391
|
+
return response
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Redeem a one-time login token and authenticate.
|
|
396
|
+
* @param token - The login token string
|
|
397
|
+
* @returns true if login succeeded, false otherwise
|
|
398
|
+
*/
|
|
399
|
+
async function loginWithToken(token: string): Promise<boolean> {
|
|
400
|
+
try {
|
|
401
|
+
const { data: response } = await api.redeemLoginToken({ token })
|
|
402
|
+
|
|
403
|
+
if (response.success === true && response.requires_verification !== true) {
|
|
404
|
+
await checkAuth()
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (response.success) {
|
|
408
|
+
emitter.emit(AuthState.LOGIN)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return response.success === true
|
|
412
|
+
} catch {
|
|
413
|
+
return false
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
321
417
|
async function checkAuth(): Promise<boolean> {
|
|
322
418
|
try {
|
|
323
419
|
const { data } = await api.getCurrentUser()
|
|
@@ -628,6 +724,22 @@ export function useAuth() {
|
|
|
628
724
|
checkAuth,
|
|
629
725
|
refreshSession,
|
|
630
726
|
|
|
727
|
+
// SMS Login
|
|
728
|
+
sendSMS,
|
|
729
|
+
verifySMS,
|
|
730
|
+
|
|
731
|
+
// SMS Login (deprecated aliases)
|
|
732
|
+
sendOTP,
|
|
733
|
+
verifyOTP,
|
|
734
|
+
|
|
735
|
+
// Email Token Login
|
|
736
|
+
sendEmailToken,
|
|
737
|
+
verifyEmailToken,
|
|
738
|
+
|
|
739
|
+
// Login Token (one-time token auth)
|
|
740
|
+
generateLoginToken,
|
|
741
|
+
loginWithToken,
|
|
742
|
+
|
|
631
743
|
// SSO Authentication (lower-level - prefer using sso.google.redirect())
|
|
632
744
|
initiateSSO,
|
|
633
745
|
loginWithSSO,
|