{% extends "base.html" %}

{% block title %}Authenticating{% endblock %}

{% block content %}
<v-container class="fill-height">
    <v-row justify="center">
        <v-col cols="12" sm="8" md="6" lg="4" class="text-center">
            <v-progress-circular
                indeterminate
                color="primary"
            ></v-progress-circular>
            <div class="mt-4">
                Please wait...
            </div>
        </v-col>
    </v-row>
</v-container>
{% endblock %}

{% block scripts %}
<script>
    const app = createApp({
        mounted() {
            const params = new URLSearchParams(window.location.search);
            const code = params.get('code');
            if (code) {
                this.processAuth(code);
            }
        },
        methods: {
            async processAuth(code) {
                try {
                    await axios.post('/auth/callback', { code });
                    window.location.href = '/dashboard';
                } catch (error) {
                    window.location.href = '/auth/signin';
                }
            }
        },
        delimiters: ['${', '}']
    });

    app.use(vuetify).mount('#app');
</script>
{% endblock %}
