-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
app.vue
49 lines (44 loc) · 1.68 KB
/
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
42
43
44
45
46
47
48
49
<script lang="ts" setup>
import { ref } from 'vue'
import { useAuth } from '#imports'
const { signIn, token, refreshToken, data, status, lastRefreshedAt, signOut, getSession } = useAuth()
const username = ref('smith')
const password = ref('hunter2')
</script>
<template>
<div>
<pre>Status: <span data-testid="status">{{ status }}</span></pre>
<pre>Data: {{ data || 'no session data present, are you logged in?' }}</pre>
<pre>Last refreshed at: {{ lastRefreshedAt || 'no refresh happened' }}</pre>
<pre>JWT token: {{ token || 'no token present, are you logged in?' }}</pre>
<pre>Refresh token: {{ refreshToken || 'N/A' }}</pre>
<form @submit.prevent="signIn({ username, password })">
<input v-model="username" type="text" placeholder="Username" data-testid="username">
<input v-model="password" type="password" placeholder="Password" data-testid="password">
<button type="submit" data-testid="submit">
sign in
</button>
</form>
<br>
<button @click="signIn({ username, password }, { callbackUrl: '/protected/globally' })">
sign in (with redirect to protected page)
</button>
<br>
<button data-testid="signout" @click="signOut({ callbackUrl: '/signout' })">
sign out
</button>
<br>
<button data-testid="refresh-required-false" @click="getSession({ required: false })">
refresh session (required: false)
</button>
<br>
<button data-testid="refresh-required-true" @click="getSession({ required: true, callbackUrl: '/' })">
refresh session (required: true)
</button>
<br>
<NuxtLink to="/login">
navigate to Login Page
</NuxtLink>
<NuxtPage />
</div>
</template>