Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

7.1 KB
Raw Blame
<script setup lang="ts">
import { Form, Head, usePage } from '@inertiajs/vue3';
import { IconEye, IconEyeOff } from '@tabler/icons-vue';
import { computed, ref } from 'vue';

import LegalLinks from '@/components/auth/LegalLinks.vue';
import SocialLogin from '@/components/auth/SocialLogin.vue';
import InputError from '@/components/InputError.vue';
import TextLink from '@/components/TextLink.vue';
import { Button } from '@/components/ui/button';
import { Checkbox } from '@/components/ui/checkbox';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Spinner } from '@/components/ui/spinner';
import {
    Tooltip,
    TooltipContent,
    TooltipProvider,
    TooltipTrigger,
} from '@/components/ui/tooltip';
import { useGuestLocale } from '@/composables/useGuestLocale';
import { usePageErrors } from '@/composables/usePageErrors';
import AuthBase from '@/layouts/AuthLayout.vue';
import { register } from '@/routes';
import { store } from '@/routes/login';
import { request } from '@/routes/password';

defineProps<{
    status?: string;
    email?: string | null;
    invite?: string | null;
}>();

const { chosen } = useGuestLocale();

const showPassword = ref(false);

const togglePasswordVisibility = (): void => {
    showPassword.value = !showPassword.value;
};

const page = usePage();
const isSelfHosted = computed(() => Boolean(page.props.selfHosted));
const pageErrors = usePageErrors();
</script>

<template>
    <AuthBase
        :title="$t('auth.login.title')"
        :status="status"
        panel
    >
        <Head :title="$t('auth.login.page_title')" />

        <div class="flex flex-col gap-6">
            <SocialLogin mode="login" :invite="invite" />

            <Form
                v-bind="store.form()"
                :reset-on-success="['password']"
                v-slot="{ errors, processing }"
                class="flex flex-col gap-4"
            >
                <input type="hidden" name="locale" :value="chosen ?? ''" />

                <input
                    v-if="invite"
                    type="hidden"
                    name="invite"
                    :value="invite"
                />

                <div class="grid gap-2">
                    <Label for="email">{{ $t('auth.login.email') }}</Label>
                    <Input
                        id="email"
                        type="email"
                        name="email"
                        data-testid="login-email"
                        autofocus
                        :tabindex="1"
                        autocomplete="email"
                        placeholder="[email protected]"
                        :default-value="email ?? ''"
                    />
                    <InputError :message="errors.email || pageErrors.email" />
                </div>

                <div class="grid gap-2">
                    <div class="flex items-center justify-between gap-2">
                        <Label for="password">{{
                            $t('auth.login.password')
                        }}</Label>
                        <TextLink
                            :href="request()"
                            class="text-sm"
                            :tabindex="5"
                        >
                            {{ $t('auth.login.forgot_password') }}
                        </TextLink>
                    </div>
                    <div class="relative">
                        <Input
                            id="password"
                            :type="showPassword ? 'text' : 'password'"
                            name="password"
                            data-testid="login-password"
                            :tabindex="2"
                            autocomplete="current-password"
                            :placeholder="$t('auth.login.password')"
                            class="pe-8"
                        />
                        <div
                            class="absolute inset-y-0 end-0 flex items-center pe-2"
                        >
                            <TooltipProvider>
                                <Tooltip>
                                    <TooltipTrigger as-child>
                                        <button
                                            type="button"
                                            :tabindex="-1"
                                            class="cursor-pointer text-muted-foreground hover:text-foreground"
                                            data-testid="login-password-toggle"
                                            @click="togglePasswordVisibility"
                                        >
                                            <IconEyeOff
                                                v-if="showPassword"
                                                class="size-4"
                                            />
                                            <IconEye v-else class="size-4" />
                                        </button>
                                    </TooltipTrigger>
                                    <TooltipContent>
                                        <p>
                                            {{
                                                showPassword
                                                    ? $t(
                                                          'auth.login.hide_password',
                                                      )
                                                    : $t(
                                                          'auth.login.show_password',
                                                      )
                                            }}
                                        </p>
                                    </TooltipContent>
                                </Tooltip>
                            </TooltipProvider>
                        </div>
                    </div>
                    <InputError :message="errors.password" />
                </div>

                <Label for="remember">
                    <Checkbox id="remember" name="remember" :tabindex="3" />
                    <span>{{ $t('auth.login.remember_me') }}</span>
                </Label>

                <Button
                    type="submit"
                    data-testid="login-submit"
                    class="w-full"
                    :tabindex="4"
                    :disabled="processing"
                    data-test="login-button"
                >
                    <Spinner v-if="processing" />
                    {{ $t('auth.login.submit') }}
                </Button>
            </Form>

            <p
                v-if="!isSelfHosted"
                class="text-center text-sm text-muted-foreground"
            >
                {{ $t('auth.login.no_account') }}
                <TextLink
                    :href="register()"
                    :tabindex="5"
                    data-testid="login-sign-up-link"
                    >{{ $t('auth.login.sign_up') }}</TextLink
                >
            </p>
        </div>

        <template #footer>
            <LegalLinks />
        </template>
    </AuthBase>
</template>