2024-08-12 07:55:15 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<v-icon icon="mdi-lan-check" size="32" color="grey-darken-3" class="mb-3" />
|
|
|
|
|
|
|
|
<h1 class="font-bold text-xl">All Done!</h1>
|
|
|
|
<p>Welcome back! You just signed in right now! We're going to direct you to dashboard...</p>
|
|
|
|
|
|
|
|
<v-expand-transition>
|
|
|
|
<v-alert v-show="error" variant="tonal" type="error" class="text-xs mb-3">
|
|
|
|
Something went wrong... {{ error }}
|
|
|
|
</v-alert>
|
|
|
|
</v-expand-transition>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { onMounted, ref } from "vue"
|
|
|
|
import { useRoute, useRouter } from "vue-router"
|
|
|
|
|
|
|
|
const config = useRuntimeConfig()
|
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
const router = useRouter()
|
2024-08-12 08:41:21 +00:00
|
|
|
const auth = useUserinfo()
|
2024-08-12 07:55:15 +00:00
|
|
|
|
|
|
|
const props = defineProps<{ loading?: boolean; currentFactor?: any; ticket?: any }>()
|
|
|
|
const emits = defineEmits(["update:loading"])
|
|
|
|
|
|
|
|
const error = ref<string | null>(null)
|
|
|
|
|
|
|
|
async function load() {
|
|
|
|
emits("update:loading", true)
|
|
|
|
await getToken(props.ticket.grant_token)
|
2024-08-12 08:41:21 +00:00
|
|
|
await auth.readProfiles()
|
2024-08-12 07:55:15 +00:00
|
|
|
setTimeout(() => callback(), 1850)
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => load())
|
|
|
|
|
|
|
|
async function getToken(tk: string) {
|
|
|
|
const res = await fetch(`${config.public.solarNetworkApi}/cgi/auth/auth/token`, {
|
|
|
|
method: "POST",
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
body: JSON.stringify({
|
|
|
|
code: tk,
|
|
|
|
grant_type: "grant_token",
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
if (res.status !== 200) {
|
|
|
|
const err = await res.text()
|
|
|
|
error.value = err
|
|
|
|
throw new Error(err)
|
|
|
|
} else {
|
2024-08-12 16:52:48 +00:00
|
|
|
const out = await res.json()
|
2024-08-12 17:08:32 +00:00
|
|
|
auth.setTokenSet(out["access_token"], out["refresh_token"])
|
2024-08-12 07:55:15 +00:00
|
|
|
error.value = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function callback() {
|
|
|
|
if (route.query["close"]) {
|
|
|
|
window.close()
|
|
|
|
} else if (route.query["redirect_uri"]) {
|
|
|
|
window.open((route.query["redirect_uri"] as string) ?? "/", "_self")
|
|
|
|
} else {
|
|
|
|
router.push("/users/me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|