aboutsummaryrefslogtreecommitdiff
path: root/extension/src/entries/popup/Components/OtpLogin.vue
blob: a2b8ac73a1318ff41ef46e1bb77889cdebb9eb37 (plain)
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
50
51
<template>
    <form class="" @submit.prevent="onSubmit">
        <fieldset class="px-4 input-container">
            <label class="">Please enter your authentication token</label>
            <textarea class="w-full input" v-model="token" rows="5" />
        </fieldset>
        <div class="flex justify-end mt-2">
            <div class="px-3">
                <button class="w-24 rounded btn sm primary">
                    <fa-icon v-if="waiting" icon="spinner" class="animate-spin" />
                    <span v-else>Submit</span>
                </button>
            </div>
        </div>
    </form>
</template>

<script setup lang="ts">
import { apiCall, useWait } from "@vnuge/vnlib.browser";
import { ref } from "vue";
import { useStore } from "../../store";

const { login } = useStore()
const { waiting } = useWait()

const token = ref('')

const onSubmit = async () => {
    await apiCall(async ({ toaster }) => {
        try{
            await login(token.value)

             toaster.form.success({
                'title': 'Login successful',
                'text': 'Successfully logged into your profile'
            })
        }
        catch(e:any){
            if('response' in e){
                throw e;
            }

            toaster.form.error({
                title: 'Failed to login',
                text: e.message
            })
        }
    })
}

</script>