Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

refactor: with-vue-3.mdx spaces on <script setup>

Roger!0ef1a5ee7f20
diff --git a/apps/docs/pages/guides/getting-started/tutorials/with-vue-3.mdx b/apps/docs/pages/guides/getting-started/tutorials/with-vue-3.mdx
index a1ec84a8c92..6d1ba416ed1 100644
--- a/apps/docs/pages/guides/getting-started/tutorials/with-vue-3.mdx
+++ b/apps/docs/pages/guides/getting-started/tutorials/with-vue-3.mdx
@@ -70,28 +70,28 @@ Let's set up a Vue component to manage logins and sign ups. We'll use Magic Link
```html title=/src/components/Auth.vue
<script setup>
- import { ref } from 'vue'
- import { supabase } from '../supabase'
-
- const loading = ref(false)
- const email = ref('')
-
- const handleLogin = async () => {
- try {
- loading.value = true
- const { error } = await supabase.auth.signInWithOtp({
- email: email.value,
- })
- if (error) throw error
- alert('Check your email for the login link!')
- } catch (error) {
- if (error instanceof Error) {
- alert(error.message)
- }
- } finally {
- loading.value = false
+import { ref } from 'vue'
+import { supabase } from '../supabase'
+
+const loading = ref(false)
+const email = ref('')
+
+const handleLogin = async () => {
+ try {
+ loading.value = true
+ const { error } = await supabase.auth.signInWithOtp({
+ email: email.value,
+ })
+ if (error) throw error
+ alert('Check your email for the login link!')
+ } catch (error) {
+ if (error instanceof Error) {
+ alert(error.message)
}
+ } finally {
+ loading.value = false
}
+}
</script>
<template>
@@ -122,80 +122,80 @@ Let's create a new component for that called `Account.vue`.
```html title=src/components/Account.vue
<script setup>
- import { supabase } from '../supabase'
- import { onMounted, ref, toRefs } from 'vue'
-
- const props = defineProps(['session'])
- const { session } = toRefs(props)
-
- const loading = ref(true)
- const username = ref('')
- const website = ref('')
- const avatar_url = ref('')
-
- onMounted(() => {
- getProfile()
- })
-
- async function getProfile() {
- try {
- loading.value = true
- const { user } = session.value
-
- let { data, error, status } = await supabase
- .from('profiles')
- .select(`username, website, avatar_url`)
- .eq('id', user.id)
- .single()
-
- if (error && status !== 406) throw error
-
- if (data) {
- username.value = data.username
- website.value = data.website
- avatar_url.value = data.avatar_url
- }
- } catch (error) {
- alert(error.message)
- } finally {
- loading.value = false
+import { supabase } from '../supabase'
+import { onMounted, ref, toRefs } from 'vue'
+
+const props = defineProps(['session'])
+const { session } = toRefs(props)
+
+const loading = ref(true)
+const username = ref('')
+const website = ref('')
+const avatar_url = ref('')
+
+onMounted(() => {
+ getProfile()
+})
+
+async function getProfile() {
+ try {
+ loading.value = true
+ const { user } = session.value
+
+ let { data, error, status } = await supabase
+ .from('profiles')
+ .select(`username, website, avatar_url`)
+ .eq('id', user.id)
+ .single()
+
+ if (error && status !== 406) throw error
+
+ if (data) {
+ username.value = data.username
+ website.value = data.website
+ avatar_url.value = data.avatar_url
}
+ } catch (error) {
+ alert(error.message)
+ } finally {
+ loading.value = false
}
+}
- async function updateProfile() {
- try {
- loading.value = true
- const { user } = session.value
-
- const updates = {
- id: user.id,
- username: username.value,
- website: website.value,
- avatar_url: avatar_url.value,
- updated_at: new Date(),
- }
+async function updateProfile() {
+ try {
+ loading.value = true
+ const { user } = session.value
+
+ const updates = {
+ id: user.id,
+ username: username.value,
+ website: website.value,
+ avatar_url: avatar_url.value,
+ updated_at: new Date(),
+ }
- let { error } = await supabase.from('profiles').upsert(updates)
+ let { error } = await supabase.from('profiles').upsert(updates)
- if (error) throw error
- } catch (error) {
- alert(error.message)
- } finally {
- loading.value = false
- }
+ if (error) throw error
+ } catch (error) {
+ alert(error.message)
+ } finally {
+ loading.value = false
}
+}
- async function signOut() {
- try {
- loading.value = true
- let { error } = await supabase.auth.signOut()
- if (error) throw error
- } catch (error) {
- alert(error.message)
- } finally {
- loading.value = false
- }
+async function signOut() {
+ try {
+ loading.value = true
+ let { error } = await supabase.auth.signOut()
+ if (error) throw error
+ } catch (error) {
+ alert(error.message)
+ } finally {
+ loading.value = false
}
+}
</script>
<template>
@@ -235,22 +235,22 @@ Now that we have all the components in place, let's update `App.vue`:
```html title=src/App.vue
<script setup>
- import { onMounted, ref } from 'vue'
- import Account from './components/Account.vue'
- import Auth from './components/Auth.vue'
- import { supabase } from './supabase'
+import { onMounted, ref } from 'vue'
+import Account from './components/Account.vue'
+import Auth from './components/Auth.vue'
+import { supabase } from './supabase'
- const session = ref()
+const session = ref()
- onMounted(() => {
- supabase.auth.getSession().then(({ data }) => {
- session.value = data.session
- })
+onMounted(() => {
+ supabase.auth.getSession().then(({ data }) => {
+ session.value = data.session
+ })
- supabase.auth.onAuthStateChange((_, _session) => {
- session.value = _session
- })
+ supabase.auth.onAuthStateChange((_, _session) => {
+ session.value = _session
})
+})
</script>
<template>
@@ -281,54 +281,54 @@ Let's create an avatar for the user so that they can upload a profile photo. We
```html title=src/components/Avatar.vue
<script setup>
- import { ref, toRefs, watch } from 'vue'
- import { supabase } from '../supabase'
-
- const prop = defineProps(['path', 'size'])
- const { path, size } = toRefs(prop)
-
- const emit = defineEmits(['upload', 'update:path'])
- const uploading = ref(false)
- const src = ref('')
- const files = ref()
-
- const downloadImage = async () => {
- try {
- const { data, error } = await supabase.storage.from('avatars').download(path.value)
- if (error) throw error
- src.value = URL.createObjectURL(data)
- } catch (error) {
- console.error('Error downloading image: ', error.message)
- }
+import { ref, toRefs, watch } from 'vue'
+import { supabase } from '../supabase'
+
+const prop = defineProps(['path', 'size'])
+const { path, size } = toRefs(prop)
+
+const emit = defineEmits(['upload', 'update:path'])
+const uploading = ref(false)
+const src = ref('')
+const files = ref()
+
+const downloadImage = async () => {
+ try {
+ const { data, error } = await supabase.storage.from('avatars').download(path.value)
+ if (error) throw error
+ src.value = URL.createObjectURL(data)
+ } catch (error) {
+ console.error('Error downloading image: ', error.message)
}
+}
- const uploadAvatar = async (evt) => {
- files.value = evt.target.files
- try {
- uploading.value = true
- if (!files.value || files.value.length === 0) {
- throw new Error('You must select an image to upload.')
- }
+const uploadAvatar = async (evt) => {
+ files.value = evt.target.files
+ try {
+ uploading.value = true
+ if (!files.value || files.value.length === 0) {
+ throw new Error('You must select an image to upload.')
+ }
- const file = files.value[0]
- const fileExt = file.name.split('.').pop()
- const filePath = `${Math.random()}.${fileExt}`
+ const file = files.value[0]
+ const fileExt = file.name.split('.').pop()
+ const filePath = `${Math.random()}.${fileExt}`
- let { error: uploadError } = await supabase.storage.from('avatars').upload(filePath, file)
+ let { error: uploadError } = await supabase.storage.from('avatars').upload(filePath, file)
- if (uploadError) throw uploadError
- emit('update:path', filePath)
- emit('upload')
- } catch (error) {
- alert(error.message)
- } finally {
- uploading.value = false
- }
+ if (uploadError) throw uploadError
+ emit('update:path', filePath)
+ emit('upload')
+ } catch (error) {
+ alert(error.message)
+ } finally {
+ uploading.value = false
}
+}
- watch(path, () => {
- if (path.value) downloadImage()
- })
+watch(path, () => {
+ if (path.value) downloadImage()
+})
</script>
<template>
@@ -365,8 +365,8 @@ And then we can add the widget to the Account page:
```html title=src/components/Account.vue
<script>
- // Import the new component
- import Avatar from './Avatar.vue'
+// Import the new component
+import Avatar from './Avatar.vue'
</script>
<template>