@saasmakers/ui 2.0.1 → 2.0.4
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/app/components/auth/AuthSocialConnect.vue +234 -0
- package/app/composables/useCapacitor.ts +47 -0
- package/app/types/auth.d.ts +42 -0
- package/app/types/global.d.ts +9 -0
- package/nuxt.config.ts +4 -0
- package/package.json +3 -1
- package/public/images/auth/AppleConnect/apple.svg +3 -0
- package/public/images/auth/GoogleConnect/google.svg +18 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { SocialLogin } from '@capgo/capacitor-social-login'
|
|
3
|
+
|
|
4
|
+
const props = withDefaults(defineProps<AuthSocialConnect>(), {
|
|
5
|
+
loading: false,
|
|
6
|
+
provider: 'apple',
|
|
7
|
+
size: 'base',
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const emit = defineEmits<{
|
|
11
|
+
error: [error: unknown]
|
|
12
|
+
success: [payload: AuthSocialConnectSuccess]
|
|
13
|
+
}>()
|
|
14
|
+
|
|
15
|
+
const { t } = useI18n()
|
|
16
|
+
const { isAndroid, platform } = useCapacitor()
|
|
17
|
+
const oauthAuthenticating = ref(false)
|
|
18
|
+
|
|
19
|
+
const buttonLoading = computed(() => {
|
|
20
|
+
return oauthAuthenticating.value || props.loading
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
onMounted(() => {
|
|
24
|
+
if (props.provider === 'google') {
|
|
25
|
+
window.addEventListener('message', processGoogleCallback)
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
onBeforeUnmount(() => {
|
|
30
|
+
if (props.provider === 'google') {
|
|
31
|
+
window.removeEventListener('message', processGoogleCallback)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
async function onStartAuthentication() {
|
|
36
|
+
oauthAuthenticating.value = true
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
if (props.provider === 'apple') {
|
|
40
|
+
if (!props.appleConfig) {
|
|
41
|
+
throw new Error('appleConfig is required when provider is apple')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const platformKey = platform.value === 'ios' ? 'ios' : 'web'
|
|
45
|
+
|
|
46
|
+
await SocialLogin.initialize({
|
|
47
|
+
apple: {
|
|
48
|
+
clientId: props.appleConfig[platformKey].appId,
|
|
49
|
+
redirectUrl: props.appleConfig[platformKey].redirectUrl,
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const { result } = await SocialLogin.login({
|
|
54
|
+
options: { scopes: ['email', 'name'] },
|
|
55
|
+
provider: 'apple',
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
emit('success', {
|
|
59
|
+
firstName: `${result.profile.givenName}`,
|
|
60
|
+
idToken: result.idToken!,
|
|
61
|
+
lastName: `${result.profile.familyName}`,
|
|
62
|
+
provider: 'apple',
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
else if (props.provider === 'google') {
|
|
66
|
+
if (!props.googleConfig) {
|
|
67
|
+
throw new Error('googleConfig is required when provider is google')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
await SocialLogin.initialize({
|
|
71
|
+
google: {
|
|
72
|
+
iOSClientId: props.googleConfig.ios.clientId,
|
|
73
|
+
redirectUrl: props.googleConfig.web.redirectUrl,
|
|
74
|
+
webClientId: props.googleConfig.web.clientId,
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const response = await SocialLogin.login({
|
|
79
|
+
options: { scopes: ['email', 'profile'] },
|
|
80
|
+
provider: 'google',
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const { idToken } = response.result as GoogleLoginResponseOnline
|
|
84
|
+
|
|
85
|
+
emit('success', {
|
|
86
|
+
idToken: idToken!,
|
|
87
|
+
provider: 'google',
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
emit('error', error)
|
|
93
|
+
|
|
94
|
+
console.error(error)
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
oauthAuthenticating.value = false
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function processGoogleCallback(event: MessageEvent) {
|
|
102
|
+
if (event.origin !== globalThis.location.origin) {
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (event.data.type === 'auth:google:success') {
|
|
107
|
+
try {
|
|
108
|
+
oauthAuthenticating.value = true
|
|
109
|
+
|
|
110
|
+
emit('success', {
|
|
111
|
+
idToken: event.data.idToken,
|
|
112
|
+
provider: 'google',
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
emit('error', error)
|
|
117
|
+
|
|
118
|
+
console.error(error)
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
oauthAuthenticating.value = false
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
<template>
|
|
128
|
+
<BaseButton
|
|
129
|
+
:class="{ hidden: isAndroid && provider === 'apple' }"
|
|
130
|
+
:color="provider === 'apple' ? 'black' : 'white'"
|
|
131
|
+
full-width
|
|
132
|
+
:loading="buttonLoading"
|
|
133
|
+
:size="size"
|
|
134
|
+
:text="provider === 'apple' ? t('continueWithApple') : t('continueWithGoogle')"
|
|
135
|
+
@click="onStartAuthentication"
|
|
136
|
+
>
|
|
137
|
+
<img
|
|
138
|
+
v-if="provider === 'apple'"
|
|
139
|
+
:alt="t('appleLogo')"
|
|
140
|
+
class="mr-2.5 w-4.5 dark:invert"
|
|
141
|
+
src="/images/auth/AppleConnect/apple.svg"
|
|
142
|
+
>
|
|
143
|
+
|
|
144
|
+
<img
|
|
145
|
+
v-else-if="provider === 'google'"
|
|
146
|
+
:alt="t('googleLogo')"
|
|
147
|
+
class="mr-2.5 w-5"
|
|
148
|
+
src="/images/auth/GoogleConnect/google.svg"
|
|
149
|
+
>
|
|
150
|
+
</BaseButton>
|
|
151
|
+
</template>
|
|
152
|
+
|
|
153
|
+
<i18n lang="json">
|
|
154
|
+
{
|
|
155
|
+
"de": {
|
|
156
|
+
"appleLogo": "Apple-Logo",
|
|
157
|
+
"continueWithApple": "Mit Apple fortfahren",
|
|
158
|
+
"continueWithGoogle": "Mit Google fortfahren",
|
|
159
|
+
"googleLogo": "Google-Logo"
|
|
160
|
+
},
|
|
161
|
+
"en": {
|
|
162
|
+
"appleLogo": "Apple logo",
|
|
163
|
+
"continueWithApple": "Continue with Apple",
|
|
164
|
+
"continueWithGoogle": "Continue with Google",
|
|
165
|
+
"googleLogo": "Google logo"
|
|
166
|
+
},
|
|
167
|
+
"es": {
|
|
168
|
+
"appleLogo": "Logo de Apple",
|
|
169
|
+
"continueWithApple": "Continuar con Apple",
|
|
170
|
+
"continueWithGoogle": "Continuar con Google",
|
|
171
|
+
"googleLogo": "Logo de Google"
|
|
172
|
+
},
|
|
173
|
+
"fr": {
|
|
174
|
+
"appleLogo": "Logo Apple",
|
|
175
|
+
"continueWithApple": "Continuer avec Apple",
|
|
176
|
+
"continueWithGoogle": "Continuer avec Google",
|
|
177
|
+
"googleLogo": "Logo Google"
|
|
178
|
+
},
|
|
179
|
+
"id": {
|
|
180
|
+
"appleLogo": "Logo Apple",
|
|
181
|
+
"continueWithApple": "Lanjutkan dengan Apple",
|
|
182
|
+
"continueWithGoogle": "Lanjutkan dengan Google",
|
|
183
|
+
"googleLogo": "Logo Google"
|
|
184
|
+
},
|
|
185
|
+
"it": {
|
|
186
|
+
"appleLogo": "Logo Apple",
|
|
187
|
+
"continueWithApple": "Continua con Apple",
|
|
188
|
+
"continueWithGoogle": "Continua con Google",
|
|
189
|
+
"googleLogo": "Logo Google"
|
|
190
|
+
},
|
|
191
|
+
"ja": {
|
|
192
|
+
"appleLogo": "Appleロゴ",
|
|
193
|
+
"continueWithApple": "Appleで続ける",
|
|
194
|
+
"continueWithGoogle": "Googleで続ける",
|
|
195
|
+
"googleLogo": "Googleロゴ"
|
|
196
|
+
},
|
|
197
|
+
"ko": {
|
|
198
|
+
"appleLogo": "Apple 로고",
|
|
199
|
+
"continueWithApple": "Apple로 계속하기",
|
|
200
|
+
"continueWithGoogle": "Google로 계속하기",
|
|
201
|
+
"googleLogo": "Google 로고"
|
|
202
|
+
},
|
|
203
|
+
"nl": {
|
|
204
|
+
"appleLogo": "Apple-logo",
|
|
205
|
+
"continueWithApple": "Doorgaan met Apple",
|
|
206
|
+
"continueWithGoogle": "Doorgaan met Google",
|
|
207
|
+
"googleLogo": "Google-logo"
|
|
208
|
+
},
|
|
209
|
+
"pl": {
|
|
210
|
+
"appleLogo": "Logo Apple",
|
|
211
|
+
"continueWithApple": "Kontynuuj z Apple",
|
|
212
|
+
"continueWithGoogle": "Kontynuuj z Google",
|
|
213
|
+
"googleLogo": "Logo Google"
|
|
214
|
+
},
|
|
215
|
+
"pt": {
|
|
216
|
+
"appleLogo": "Logótipo da Apple",
|
|
217
|
+
"continueWithApple": "Continuar com Apple",
|
|
218
|
+
"continueWithGoogle": "Continuar com Google",
|
|
219
|
+
"googleLogo": "Logótipo do Google"
|
|
220
|
+
},
|
|
221
|
+
"pt-BR": {
|
|
222
|
+
"appleLogo": "Logo da Apple",
|
|
223
|
+
"continueWithApple": "Continuar com Apple",
|
|
224
|
+
"continueWithGoogle": "Continuar com Google",
|
|
225
|
+
"googleLogo": "Logo do Google"
|
|
226
|
+
},
|
|
227
|
+
"vi": {
|
|
228
|
+
"appleLogo": "Logo Apple",
|
|
229
|
+
"continueWithApple": "Tiếp tục với Apple",
|
|
230
|
+
"continueWithGoogle": "Tiếp tục với Google",
|
|
231
|
+
"googleLogo": "Logo Google"
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
</i18n>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Capacitor } from '@capacitor/core'
|
|
2
|
+
|
|
3
|
+
export default function useCapacitor() {
|
|
4
|
+
const platform = ref(Capacitor.getPlatform() as Platforms)
|
|
5
|
+
|
|
6
|
+
const isAndroid = computed(() => {
|
|
7
|
+
return platform.value === 'android'
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const isIOS = computed(() => {
|
|
11
|
+
return platform.value === 'ios'
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const isNative = computed(() => {
|
|
15
|
+
return Capacitor.isNativePlatform()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const isWeb = computed(() => {
|
|
19
|
+
return platform.value === 'web'
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const getPlatform = () => {
|
|
23
|
+
if (isAndroid.value) {
|
|
24
|
+
return 'android'
|
|
25
|
+
}
|
|
26
|
+
else if (isIOS.value) {
|
|
27
|
+
return 'ios'
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return 'web'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isPluginAvailable = (pluginName: string) => {
|
|
35
|
+
return Capacitor.isPluginAvailable(pluginName)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
getPlatform,
|
|
40
|
+
isAndroid,
|
|
41
|
+
isIOS,
|
|
42
|
+
isNative,
|
|
43
|
+
isPluginAvailable,
|
|
44
|
+
isWeb,
|
|
45
|
+
platform,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface AuthSocialConnect {
|
|
2
|
+
appleConfig?: AuthSocialConnectAppleConfig
|
|
3
|
+
googleConfig?: AuthSocialConnectGoogleConfig
|
|
4
|
+
loading?: boolean
|
|
5
|
+
provider: AuthSocialConnectProvider
|
|
6
|
+
size?: BaseButtonSize
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface AuthSocialConnectAppleConfig {
|
|
10
|
+
ios: {
|
|
11
|
+
appId: string
|
|
12
|
+
redirectUrl: string
|
|
13
|
+
}
|
|
14
|
+
web: {
|
|
15
|
+
appId: string
|
|
16
|
+
redirectUrl: string
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface AuthSocialConnectGoogleConfig {
|
|
21
|
+
ios: {
|
|
22
|
+
clientId: string
|
|
23
|
+
}
|
|
24
|
+
web: {
|
|
25
|
+
clientId: string
|
|
26
|
+
redirectUrl: string
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type AuthSocialConnectProvider = 'apple' | 'google'
|
|
31
|
+
|
|
32
|
+
export type AuthSocialConnectSuccess
|
|
33
|
+
= | {
|
|
34
|
+
firstName?: string
|
|
35
|
+
idToken: string
|
|
36
|
+
lastName?: string
|
|
37
|
+
provider: 'apple'
|
|
38
|
+
}
|
|
39
|
+
| {
|
|
40
|
+
idToken: string
|
|
41
|
+
provider: 'google'
|
|
42
|
+
}
|
package/app/types/global.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { Directive } from 'vue'
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
|
+
// Auth
|
|
5
|
+
type AuthSocialConnect = import('./auth').AuthSocialConnect
|
|
6
|
+
type AuthSocialConnectAppleConfig = import('./auth').AuthSocialConnectAppleConfig
|
|
7
|
+
type AuthSocialConnectGoogleConfig = import('./auth').AuthSocialConnectGoogleConfig
|
|
8
|
+
type AuthSocialConnectProvider = import('./auth').AuthSocialConnectProvider
|
|
9
|
+
type AuthSocialConnectSuccess = import('./auth').AuthSocialConnectSuccess
|
|
10
|
+
|
|
4
11
|
// Bases
|
|
5
12
|
type BaseAlert = import('./bases').BaseAlert
|
|
6
13
|
type BaseAlignment = import('./bases').BaseAlignment
|
|
@@ -67,6 +74,8 @@ declare global {
|
|
|
67
74
|
type ChartistLineChartData = import('chartist').LineChartData
|
|
68
75
|
type ChartistOptions = import('chartist').Options
|
|
69
76
|
type ChartistPieChartData = import('chartist').PieChartData
|
|
77
|
+
type GoogleLoginResponseOnline = import('@capgo/capacitor-social-login').GoogleLoginResponseOnline
|
|
78
|
+
type Platforms = import('@saasmakers/shared').Platforms
|
|
70
79
|
|
|
71
80
|
// Fields
|
|
72
81
|
type FieldAvatar = import('./fields').FieldAvatar
|
package/nuxt.config.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saasmakers/ui",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Reusable Nuxt UI components for SaaS Makers projects",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
"uno.config.ts"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"@capacitor/core": "8.4.0",
|
|
24
25
|
"@capacitor/preferences": "8.0.1",
|
|
26
|
+
"@capgo/capacitor-social-login": "8.3.22",
|
|
25
27
|
"@nuxt/icon": "2.2.3",
|
|
26
28
|
"@nuxt/scripts": "0.13.2",
|
|
27
29
|
"@nuxtjs/color-mode": "3.5.2",
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="842" height="1e3" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill="#FFFFFF" d="M702 960c-54.2 52.6-114 44.4-171 19.6-60.6-25.3-116-26.9-180 0-79.7 34.4-122 24.4-170-19.6-271-279-231-704 77-720 74.7 4 127 41.3 171 44.4 65.4-13.3 128-51.4 198-46.4 84.1 6.8 147 40 189 99.7-173 104-132 332 26.9 396-31.8 83.5-72.6 166-141 227zM423 237C414.9 113 515.4 11 631 1c15.9 143-130 250-208 236z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg width="47px" height="48px" viewBox="0 0 47 48" version="1.1"
|
|
3
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
4
|
+
xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
5
|
+
<!-- Generator: Sketch 53.2 (72643) - https://sketchapp.com -->
|
|
6
|
+
<title>Google_color</title>
|
|
7
|
+
<desc>Created with Sketch.</desc>
|
|
8
|
+
<g id="Icons" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
9
|
+
<g id="Color-" transform="translate(-401.000000, -860.000000)">
|
|
10
|
+
<g id="Google" transform="translate(401.000000, 860.000000)">
|
|
11
|
+
<path d="M9.82727273,24 C9.82727273,22.4757333 10.0804318,21.0144 10.5322727,19.6437333 L2.62345455,13.6042667 C1.08206818,16.7338667 0.213636364,20.2602667 0.213636364,24 C0.213636364,27.7365333 1.081,31.2608 2.62025,34.3882667 L10.5247955,28.3370667 C10.0772273,26.9728 9.82727273,25.5168 9.82727273,24" id="Fill-1" fill="#FBBC05"></path>
|
|
12
|
+
<path d="M23.7136364,10.1333333 C27.025,10.1333333 30.0159091,11.3066667 32.3659091,13.2266667 L39.2022727,6.4 C35.0363636,2.77333333 29.6954545,0.533333333 23.7136364,0.533333333 C14.4268636,0.533333333 6.44540909,5.84426667 2.62345455,13.6042667 L10.5322727,19.6437333 C12.3545909,14.112 17.5491591,10.1333333 23.7136364,10.1333333" id="Fill-2" fill="#EA4335"></path>
|
|
13
|
+
<path d="M23.7136364,37.8666667 C17.5491591,37.8666667 12.3545909,33.888 10.5322727,28.3562667 L2.62345455,34.3946667 C6.44540909,42.1557333 14.4268636,47.4666667 23.7136364,47.4666667 C29.4455,47.4666667 34.9177955,45.4314667 39.0249545,41.6181333 L31.5177727,35.8144 C29.3995682,37.1488 26.7323182,37.8666667 23.7136364,37.8666667" id="Fill-3" fill="#34A853"></path>
|
|
14
|
+
<path d="M46.1454545,24 C46.1454545,22.6133333 45.9318182,21.12 45.6113636,19.7333333 L23.7136364,19.7333333 L23.7136364,28.8 L36.3181818,28.8 C35.6879545,31.8912 33.9724545,34.2677333 31.5177727,35.8144 L39.0249545,41.6181333 C43.3393409,37.6138667 46.1454545,31.6490667 46.1454545,24" id="Fill-4" fill="#4285F4"></path>
|
|
15
|
+
</g>
|
|
16
|
+
</g>
|
|
17
|
+
</g>
|
|
18
|
+
</svg>
|