Skip to content

Commit d8b4d84

Browse files
committed
feat: make the auth view reactivity
1 parent 603c272 commit d8b4d84

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,27 @@ The Auth component is currently shipped with the following views:
211211
- [Update password](https://supabase.com/docs/guides/auth/auth-password-reset#update-password)
212212
- [Forgotten password](https://supabase.com/docs/guides/auth/auth-password-reset#sending-password-reset-email)
213213

214+
```html
215+
<template>
216+
...
217+
<Auth
218+
:supabaseClient="supabaseClient"
219+
:providers="['google']"
220+
v-model:view="authView"
221+
:redirectTo="redirectTo"
222+
/>
223+
...
224+
</tempalte>
225+
226+
<script setup lang="ts">
227+
const authView = ref('sign_in')
228+
229+
const redirectTo = computed(() => {
230+
return authView === 'forgotten_password' ? FORGOTTEN_PASSWORD_URL : REDIRECT_TO_URL
231+
})
232+
</script>
233+
```
234+
214235
We are planning on adding more views in the future. Follow along on this repo.
215236

216237
## Customization

packages/auth/Auth.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ const props = withDefaults(defineProps<AuthProps>(), {
9090
otpType: 'email'
9191
})
9292
93+
const emit = defineEmits(['update:view'])
94+
9395
const authView = ref<ViewType>(props.view)
94-
const setAuthView = (newView: ViewType) => (authView.value = newView)
96+
const setAuthView = (newView: ViewType) => {
97+
emit('update:view', newView)
98+
authView.value = newView
99+
}
95100
96101
provide(AuthViewKey, {
97102
authView,

packages/auth/SocialAuth.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
</template>
1919
<template v-if="verticalSocialLayout">
2020
{{
21-
template(labels?.social_provider_text?.replace('_oidc', '') as string, {
22-
provider: capitalize(provider.replace('_oidc', ''))
23-
})
21+
template(
22+
labels?.social_provider_text?.replace('_oidc', '') as string,
23+
{
24+
provider: capitalize(provider.replace('_oidc', ''))
25+
}
26+
)
2427
}}
2528
</template>
2629
</Button>
@@ -87,14 +90,15 @@ const labels = computed(
8790
const handleProviderSignIn = async (provider: Provider) => {
8891
error.value = ''
8992
isLoading.value = true
90-
const { error: err } = await props.supabaseClient.auth.signInWithOAuth({
93+
const { data, error: err } = await props.supabaseClient.auth.signInWithOAuth({
9194
provider,
9295
options: {
9396
redirectTo: props.redirectTo,
9497
scopes: props.providerScopes?.[provider],
9598
queryParams: props.queryParams
9699
}
97100
})
101+
// console.log(data)
98102
if (err) error.value = err.message
99103
isLoading.value = false
100104
}

src/App.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
}
5858
}"
5959
:supabaseClient="supabaseClient"
60-
:view="view.id"
60+
v-model:view="view"
6161
:providers="['github', 'google', 'twitter']"
6262
:socialLayout="socialLayout"
6363
:theme="theme"
@@ -154,11 +154,10 @@
154154
v-for="v in views"
155155
:key="v.id"
156156
:value="v.id"
157-
@click.prevent="view = v"
157+
@click.prevent="view = v.id"
158158
class="text-white border-0 py-2 px-6 focus:outline-none rounded text-sm"
159159
:style="{
160-
background:
161-
view.id === v.id ? brandColor : backgroundColor
160+
background: view === v.id ? brandColor : backgroundColor
162161
}"
163162
>
164163
{{ v.title }}
@@ -194,6 +193,11 @@ import UserContextProvider, {
194193
const supabaseClient = createClient(
195194
import.meta.env.VITE_SUPABASE_URL,
196195
import.meta.env.VITE_SUPABASE_ANON_KEY
196+
// {
197+
// auth: {
198+
// debug: true
199+
// }
200+
// }
197201
)
198202
199203
useSEOHeader()
@@ -231,7 +235,7 @@ const views: { id: ViewType; title: string }[] = [
231235
const brandColor = ref(colors[0])
232236
const borderRadius = ref(radii[0])
233237
const socialLayout = ref(socialAlignments[0])
234-
const view = ref(views[0])
238+
const view = ref(views[0].id)
235239
236240
const backgroundColor = computed(() => {
237241
const opacity = isDark.value ? '.2' : '.48'

0 commit comments

Comments
 (0)