@zvonimirsun/iszy-nuxt-auth-layer 0.1.6 → 0.1.8

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.
@@ -12,7 +12,7 @@ const props = defineProps<{
12
12
  const userStore = useUserStore()
13
13
  const authFeatures = await userStore.getAuthFeatures()
14
14
  const toast = useToast()
15
- const publicRegister = computed(() => authFeatures.authMode !== 'sso' && authFeatures.publicRegister)
15
+ const publicRegister = computed(() => authFeatures.publicRegister)
16
16
  const loginPath = computed(() => `/login?redirect=${encodeURIComponent(props.loginRedirect || '/settings')}`)
17
17
  const adminRoleNames = new Set([RoleEnum.ADMIN, RoleEnum.SUPERADMIN]) as Set<string>
18
18
  const showAdminLink = computed(() => {
@@ -23,13 +23,13 @@ const showAdminLink = computed(() => {
23
23
 
24
24
  /** ************** 三方登录绑定 ***************/
25
25
 
26
- type ThirdPartyType = 'github' | 'linuxdo' | 'sso'
26
+ type LoginProviderType = 'github' | 'linuxdo' | 'sso'
27
27
  type ThirdPartyProfile = {
28
- [key in ThirdPartyType]?: string
28
+ [key in LoginProviderType]?: string
29
29
  }
30
30
 
31
31
  const thirdParties: {
32
- type: ThirdPartyType
32
+ type: Exclude<LoginProviderType, 'sso'>
33
33
  title: string
34
34
  icon: string
35
35
  }[] = [
@@ -43,13 +43,14 @@ const thirdParties: {
43
43
  title: 'LINUX DO',
44
44
  icon: 'i-iszy-auth:linuxdo',
45
45
  },
46
- {
47
- type: 'sso',
48
- title: authFeatures.sso.title,
49
- icon: 'i-lucide:shield-check',
50
- },
51
46
  ]
52
47
 
48
+ const ssoProvider = {
49
+ type: 'sso' as const,
50
+ title: authFeatures.sso.title,
51
+ icon: 'i-lucide:shield-check',
52
+ }
53
+
53
54
  const binding = ref(false)
54
55
  let pollIndex: number | null = null
55
56
 
@@ -61,7 +62,7 @@ onBeforeUnmount(() => {
61
62
  window.removeEventListener('message', bindCallback)
62
63
  })
63
64
 
64
- async function bind(type: ThirdPartyType, title = '绑定第三方登录', width = 500, height = 600) {
65
+ async function bind(type: LoginProviderType, title = '绑定第三方登录', width = 500, height = 600) {
65
66
  if (isThirdPartyBound(type)) {
66
67
  return
67
68
  }
@@ -71,8 +72,8 @@ async function bind(type: ThirdPartyType, title = '绑定第三方登录', width
71
72
  }
72
73
  binding.value = true
73
74
  window.addEventListener('message', bindCallback)
74
- const top = (window.screen.height - width) / 2
75
- const left = (window.screen.width - height) / 2
75
+ const top = (window.screen.height - height) / 2
76
+ const left = (window.screen.width - width) / 2
76
77
  const page = window.open(`/api/oauth/${type}/bind`, title, `popup,width=${width},height=${height},top=${top},left=${left}`)
77
78
  if (!page) {
78
79
  binding.value = false
@@ -117,7 +118,7 @@ async function bindCallback(e: MessageEvent<{
117
118
  }
118
119
  }
119
120
 
120
- async function unbind(type: ThirdPartyType) {
121
+ async function unbind(type: LoginProviderType) {
121
122
  if (!isThirdPartyBound(type)) {
122
123
  return
123
124
  }
@@ -130,7 +131,7 @@ async function unbind(type: ThirdPartyType) {
130
131
  }
131
132
  }
132
133
 
133
- function isThirdPartyBound(type: ThirdPartyType) {
134
+ function isThirdPartyBound(type: LoginProviderType) {
134
135
  return !!(userStore.profile as ThirdPartyProfile | undefined)?.[type]
135
136
  }
136
137
 
@@ -302,6 +303,22 @@ async function removeDevice(options: {
302
303
  </div>
303
304
  </div>
304
305
  </div>
306
+ <div class="flex items-start gap-2">
307
+ <div class="w-20 text-right">
308
+ {{ ssoProvider.title }}:
309
+ </div>
310
+ <div class="flex gap-2 items-center">
311
+ <div class="flex gap-2 items-center">
312
+ <UIcon :name="ssoProvider.icon" class="size-5" />
313
+ </div>
314
+ <UButton v-if="isThirdPartyBound(ssoProvider.type)" variant="link" class="p-0 cursor-pointer" @click="unbind(ssoProvider.type)">
315
+ 解绑
316
+ </UButton>
317
+ <UButton v-else variant="link" class="p-0 cursor-pointer" @click="bind(ssoProvider.type, ssoProvider.title)">
318
+ 绑定
319
+ </UButton>
320
+ </div>
321
+ </div>
305
322
  </div>
306
323
  <div class="flex gap-2">
307
324
  <UModal
@@ -130,8 +130,8 @@ function thirdPartyLogin(url: string, title = '第三方登录', width = 500, he
130
130
  loading.value = true
131
131
  error.value = undefined
132
132
  window.addEventListener('message', thirdPartyLoginCallback)
133
- const top = (window.screen.height - width) / 2
134
- const left = (window.screen.width - height) / 2
133
+ const top = (window.screen.height - height) / 2
134
+ const left = (window.screen.width - width) / 2
135
135
  const page = window.open(url, title, `popup,width=${width},height=${height},top=${top},left=${left}`)
136
136
  if (!page) {
137
137
  loading.value = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zvonimirsun/iszy-nuxt-auth-layer",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "ISZY Nuxt 应用共享认证 layer。",