-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathapp.vue
41 lines (34 loc) · 963 Bytes
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<script setup lang="ts">
import { useLogtoClient, useLogtoUser, useState, callOnce } from '#imports';
const client = useLogtoClient();
const accessToken = useState<string | undefined>('access-token');
await callOnce(async () => {
if (!client) {
throw new Error('Logto client is not available');
}
if (!(await client.isAuthenticated())) {
return;
}
try {
accessToken.value = await client.getAccessToken();
} catch (error) {
console.error('Failed to get access token', error);
}
});
const user = useLogtoUser();
</script>
<template>
<div>
<p>Logto Nuxt 3 sample</p>
<p v-if="Boolean(user)">Authenticated</p>
<ul v-if="Boolean(user)">
<li v-for="(value, key) in user">
<b>{{ key }}:</b> {{ value }}
</li>
</ul>
<p v-if="Boolean(user)">Access token: {{ accessToken }}</p>
<a :href="`/sign-${ user ? 'out' : 'in' }`">
Sign {{ user ? 'out' : 'in' }}
</a>
</div>
</template>