Skip to content

Commit 1d57518

Browse files
committed
chore: update playground
1 parent 4ddcb50 commit 1d57518

File tree

4 files changed

+140
-3
lines changed

4 files changed

+140
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script lang="ts" setup>
2+
import { getToken } from 'firebase/app-check'
3+
import { onMounted } from 'vue'
4+
import { useAppCheckToken, useAppCheck } from 'vuefire'
5+
6+
const token = useAppCheckToken()
7+
const appCheck = useAppCheck()
8+
9+
onMounted(async () => {
10+
if (appCheck) {
11+
console.log('appcheck token', await getToken(appCheck))
12+
} else {
13+
console.log('App Check not initialized')
14+
}
15+
})
16+
</script>
17+
18+
<template>
19+
<div>
20+
<h1>App Check</h1>
21+
<p>Token: {{ token }}</p>
22+
</div>
23+
</template>

packages/nuxt/playground/pages/authentication.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let credential: AuthCredential | null = null
3131
const route = useRoute()
3232
const router = useRouter()
3333
34-
// automatically redirect the user if they are logged in but was rejected on the server beacuse of an outdated cookie
34+
// automatically redirect the user if they are logged in but was rejected on the server because of an outdated cookie
3535
onMounted(async () => {
3636
const currentUser = await getCurrentUser()
3737
if (

packages/nuxt/playground/pages/firestore-secure-doc.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const db = useFirestore()
1010
const user = useCurrentUser()
1111
const secretRef = computed(() => user.value ? doc(db, 'secrets', user.value.uid) : null)
1212
13-
const secret = useDocument(secretRef)
13+
const { data:secret, pending: isSecretLoading } = useDocument(secretRef)
1414
1515
const textSecret = ref('')
1616
function setSecret() {
@@ -25,7 +25,7 @@ function setSecret() {
2525
<p v-if="!user">
2626
Log in in the authentication page to test this.
2727
</p>
28-
<template v-else>
28+
<template v-else-if="secret">
2929
<p>Secret Data for user {{ user.displayName }} ({{ user.uid }})</p>
3030
<pre v-if="secret">{{ secret }}</pre>
3131
<div v-else>
@@ -36,5 +36,8 @@ function setSecret() {
3636
</form>
3737
</div>
3838
</template>
39+
<template v-else-if="isSecretLoading">
40+
<p>Loading...</p>
41+
</template>
3942
</div>
4043
</template>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<script lang="ts" setup>
2+
import { computed, ref, watch } from 'vue'
3+
import { useFileDialog } from '@vueuse/core'
4+
import { useFirebaseStorage, useStorageFile, useCurrentUser } from 'vuefire'
5+
import {
6+
deleteObject,
7+
ref as storageRef,
8+
type StorageReference,
9+
} from 'firebase/storage'
10+
11+
const filename = ref<string>()
12+
const { files, open, reset } = useFileDialog()
13+
// automatically set the filename when a file is selected
14+
watch(
15+
() => files.value?.item(0)?.name,
16+
(name) => {
17+
// avoid clearing out the filename
18+
if (name && !filename.value) {
19+
filename.value = name
20+
}
21+
}
22+
)
23+
24+
const user = useCurrentUser()
25+
26+
const storage = useFirebaseStorage()
27+
const storageBucket = storageRef(storage, 'demo/' + user.value?.uid || '')
28+
const storageSource = computed(() =>
29+
filename.value ? storageRef(storageBucket, filename.value) : null
30+
)
31+
32+
const {
33+
uploadProgress: progress,
34+
url,
35+
uploadError: error,
36+
snapshot,
37+
uploadTask,
38+
metadata,
39+
upload,
40+
} = useStorageFile(storageSource)
41+
42+
// TODO: move to tests
43+
// useStorageTask(storageSource, null).data
44+
// // should fail
45+
// useStorageTask(storageSource, new Blob()).data
46+
47+
function uploadPicture() {
48+
const data = files.value?.item(0)
49+
if (data) {
50+
upload(data)
51+
}
52+
}
53+
</script>
54+
55+
<template>
56+
<form @submit.prevent="uploadPicture">
57+
<fieldset :disabled="!!uploadTask">
58+
<button
59+
type="button"
60+
@click="open({ accept: 'image/*', multiple: false })"
61+
>
62+
<template v-if="files?.length">
63+
<template v-if="files.length === 1"
64+
>Selected file: {{ files.item(0)!.name }} (Click to select
65+
another)</template
66+
>
67+
<template v-else>{{ files.length }} files (you hacker 😢)</template>
68+
</template>
69+
<template v-else> Select one picture </template>
70+
</button>
71+
72+
<br />
73+
74+
<label>
75+
Filename to use (leave blank to auto generate)
76+
<input type="text" v-model="filename" />
77+
</label>
78+
79+
<br />
80+
81+
<button>Upload</button>
82+
</fieldset>
83+
</form>
84+
85+
<div v-if="error">
86+
<p>
87+
Error: {{ error.name }} ({{ error.code }})
88+
<br />
89+
{{ error.message }}
90+
<br />
91+
</p>
92+
<pre v-if="error.stack">{{ error.stack }}</pre>
93+
<pre v-if="error.customData">{{ error.customData }}</pre>
94+
</div>
95+
<div v-else-if="progress != null">
96+
<progress max="1" :value="progress">{{ progress * 100 }}%</progress>
97+
</div>
98+
<p v-if="url">
99+
Success: {{ url }}
100+
<br />
101+
<img :src="url" />
102+
</p>
103+
<p v-if="snapshot">File: {{ snapshot.ref.name }}</p>
104+
<pre>{{ metadata }}</pre>
105+
106+
<p v-if="storageSource">Select a new file to simply update it</p>
107+
<p v-else>Clear the input to delete the file.</p>
108+
<button @click="deleteObject(storageSource!)" :disabled="!storageSource">
109+
Delete the picture
110+
</button>
111+
</template>

0 commit comments

Comments
 (0)