@bagelink/auth 1.9.59 → 1.9.63
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 +36 -32
- package/dist/index.cjs +101 -127
- package/dist/index.mjs +101 -127
- package/dist/sso.d.ts +2 -2
- package/dist/types.d.ts +70 -24
- package/dist/useAuth.d.ts +19 -20
- package/package.json +1 -1
- package/src/api.ts +81 -82
- package/src/sso.ts +26 -24
- package/src/types.ts +77 -28
- package/src/useAuth.ts +19 -51
package/src/useAuth.ts
CHANGED
|
@@ -221,20 +221,20 @@ export function useAuth() {
|
|
|
221
221
|
|
|
222
222
|
// Set SSO auth context (allows sso.google.redirect() etc. to work)
|
|
223
223
|
const authMethods = {
|
|
224
|
-
initiateSSO: async (params: SSOInitiateRequest) => {
|
|
225
|
-
const { data } = await api.initiateSSO(params)
|
|
224
|
+
initiateSSO: async (provider: SSOProvider, params: SSOInitiateRequest) => {
|
|
225
|
+
const { data } = await api.initiateSSO(provider, params)
|
|
226
226
|
return data.authorization_url
|
|
227
227
|
},
|
|
228
|
-
loginWithSSO: async (params: SSOCallbackRequest) => {
|
|
229
|
-
const { data } = await api.ssoCallback(params)
|
|
228
|
+
loginWithSSO: async (provider: SSOProvider, params: SSOCallbackRequest) => {
|
|
229
|
+
const { data } = await api.ssoCallback(provider, params)
|
|
230
230
|
if (data.success === true && data.requires_verification !== true) {
|
|
231
231
|
await checkAuth()
|
|
232
232
|
}
|
|
233
233
|
emitter.emit(AuthState.LOGIN)
|
|
234
234
|
return data
|
|
235
235
|
},
|
|
236
|
-
linkSSOProvider: async (params: SSOLinkRequest) => {
|
|
237
|
-
await api.linkSSOProvider(params)
|
|
236
|
+
linkSSOProvider: async (provider: SSOProvider, params: SSOLinkRequest) => {
|
|
237
|
+
await api.linkSSOProvider(provider, params)
|
|
238
238
|
await checkAuth()
|
|
239
239
|
},
|
|
240
240
|
unlinkSSOProvider: async (provider: SSOProvider) => {
|
|
@@ -292,10 +292,7 @@ export function useAuth() {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
async function login(credentials: { email: string, password: string }) {
|
|
295
|
-
const { data } = await api.login(
|
|
296
|
-
credentials.email.toLowerCase(),
|
|
297
|
-
credentials.password
|
|
298
|
-
)
|
|
295
|
+
const { data } = await api.login(credentials)
|
|
299
296
|
|
|
300
297
|
// If successful and not requiring verification, fetch user data and tenants
|
|
301
298
|
if (data.success === true && data.requires_verification !== true) {
|
|
@@ -403,7 +400,7 @@ export function useAuth() {
|
|
|
403
400
|
}
|
|
404
401
|
|
|
405
402
|
async function forgotPassword(email: string) {
|
|
406
|
-
await api.forgotPassword(email)
|
|
403
|
+
await api.forgotPassword({ email })
|
|
407
404
|
}
|
|
408
405
|
|
|
409
406
|
async function verifyResetToken(token: string) {
|
|
@@ -432,18 +429,6 @@ export function useAuth() {
|
|
|
432
429
|
emitter.emit(AuthState.PROFILE_UPDATE)
|
|
433
430
|
}
|
|
434
431
|
|
|
435
|
-
async function activateAccount(accountId: string) {
|
|
436
|
-
await api.activateAccount(accountId)
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
async function deactivateAccount(accountId: string) {
|
|
440
|
-
await api.deactivateAccount(accountId)
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
async function deleteAccount(accountId: string) {
|
|
444
|
-
await api.deleteAccount(accountId)
|
|
445
|
-
}
|
|
446
|
-
|
|
447
432
|
async function deleteCurrentUser() {
|
|
448
433
|
await api.deleteCurrentUser()
|
|
449
434
|
accountInfo.value = null
|
|
@@ -454,7 +439,7 @@ export function useAuth() {
|
|
|
454
439
|
}
|
|
455
440
|
|
|
456
441
|
async function verifyEmail(token: string) {
|
|
457
|
-
await api.verifyEmail(token)
|
|
442
|
+
await api.verifyEmail({ token })
|
|
458
443
|
// Refresh user data to get updated verification status
|
|
459
444
|
await checkAuth()
|
|
460
445
|
emitter.emit(AuthState.EMAIL_VERIFIED)
|
|
@@ -465,24 +450,16 @@ export function useAuth() {
|
|
|
465
450
|
emitter.emit(AuthState.SESSION_REFRESH)
|
|
466
451
|
}
|
|
467
452
|
|
|
468
|
-
async function getSessions(
|
|
469
|
-
|
|
470
|
-
if (id === undefined || id === '') {
|
|
471
|
-
throw new Error('No account ID available')
|
|
472
|
-
}
|
|
473
|
-
return api.getSessions(id)
|
|
453
|
+
async function getSessions() {
|
|
454
|
+
return api.getSessions()
|
|
474
455
|
}
|
|
475
456
|
|
|
476
457
|
async function revokeSession(sessionToken: string) {
|
|
477
458
|
await api.revokeSession(sessionToken)
|
|
478
459
|
}
|
|
479
460
|
|
|
480
|
-
async function revokeAllSessions(
|
|
481
|
-
|
|
482
|
-
if (id === undefined || id === '') {
|
|
483
|
-
throw new Error('No account ID available')
|
|
484
|
-
}
|
|
485
|
-
await api.revokeAllSessions(id)
|
|
461
|
+
async function revokeAllSessions() {
|
|
462
|
+
await api.revokeAllSessions()
|
|
486
463
|
}
|
|
487
464
|
|
|
488
465
|
// ============================================
|
|
@@ -493,21 +470,19 @@ export function useAuth() {
|
|
|
493
470
|
* Initiate SSO login flow
|
|
494
471
|
* @returns Authorization URL to redirect user to
|
|
495
472
|
*/
|
|
496
|
-
async function initiateSSO(params: SSOInitiateRequest) {
|
|
497
|
-
const { data } = await api.initiateSSO(params)
|
|
473
|
+
async function initiateSSO(provider: SSOProvider, params: SSOInitiateRequest) {
|
|
474
|
+
const { data } = await api.initiateSSO(provider, params)
|
|
498
475
|
return data.authorization_url
|
|
499
476
|
}
|
|
500
477
|
|
|
501
478
|
/**
|
|
502
479
|
* Complete SSO login after callback from provider
|
|
503
480
|
*/
|
|
504
|
-
async function loginWithSSO(params: SSOCallbackRequest) {
|
|
505
|
-
const { data } = await api.ssoCallback(params)
|
|
481
|
+
async function loginWithSSO(provider: SSOProvider, params: SSOCallbackRequest) {
|
|
482
|
+
const { data } = await api.ssoCallback(provider, params)
|
|
506
483
|
|
|
507
|
-
// If successful and not requiring verification, fetch user data and tenants
|
|
508
484
|
if (data.success === true && data.requires_verification !== true) {
|
|
509
485
|
await checkAuth()
|
|
510
|
-
// checkAuth now calls loadTenants automatically
|
|
511
486
|
}
|
|
512
487
|
|
|
513
488
|
emitter.emit(AuthState.LOGIN)
|
|
@@ -517,9 +492,8 @@ export function useAuth() {
|
|
|
517
492
|
/**
|
|
518
493
|
* Link an SSO provider to the current account
|
|
519
494
|
*/
|
|
520
|
-
async function linkSSOProvider(params: SSOLinkRequest) {
|
|
521
|
-
await api.linkSSOProvider(params)
|
|
522
|
-
// Refresh user data to get updated authentication methods
|
|
495
|
+
async function linkSSOProvider(provider: SSOProvider, params: SSOLinkRequest) {
|
|
496
|
+
await api.linkSSOProvider(provider, params)
|
|
523
497
|
await checkAuth()
|
|
524
498
|
}
|
|
525
499
|
|
|
@@ -528,7 +502,6 @@ export function useAuth() {
|
|
|
528
502
|
*/
|
|
529
503
|
async function unlinkSSOProvider(provider: SSOProvider) {
|
|
530
504
|
await api.unlinkSSOProvider(provider)
|
|
531
|
-
// Refresh user data to get updated authentication methods
|
|
532
505
|
await checkAuth()
|
|
533
506
|
}
|
|
534
507
|
|
|
@@ -583,11 +556,6 @@ export function useAuth() {
|
|
|
583
556
|
sendVerification,
|
|
584
557
|
verifyEmail,
|
|
585
558
|
|
|
586
|
-
// Admin Actions
|
|
587
|
-
activateAccount,
|
|
588
|
-
deactivateAccount,
|
|
589
|
-
deleteAccount,
|
|
590
|
-
|
|
591
559
|
// Session Management
|
|
592
560
|
getSessions,
|
|
593
561
|
revokeSession,
|