<script setup lang="ts">
import {onMounted} from "vue";
import {account} from "@/lib/appwrite";
import {useSessionStore} from "@/stores/session";
import type {Models} from "appwrite";

const sessionStore = useSessionStore();
onMounted(async () => {
  console.log('Magic Callback mounted');
  const params = new URLSearchParams(window.location.search);
  const secret = params.get('secret') || '';
  const userId = params.get('userId') || '';

  account.updateMagicURLSession(userId, secret).then((user: Models.Session) => {
    console.log('Magic URL session updated');
    sessionStore.session = user;
  }).catch((e) => {
    console.error('Error updating magic URL session:', e);
  });
});
</script>

<template>
  <div>
    <h1>Magic Callback</h1>
  </div>
</template>

<style scoped>

</style>