fix .env.production
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {onMounted, ref} from "vue"
|
import {onMounted, ref} from "vue"
|
||||||
import {useRouter} from "vue-router";
|
import {useRouter} from "vue-router";
|
||||||
import {InputText, Password, Button} from "primevue";
|
import {Button, InputText, Password} from "primevue";
|
||||||
import {useUserStore} from "@/stores/userStore";
|
import {useUserStore} from "@/stores/userStore";
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -19,13 +19,14 @@ const userStore = useUserStore()
|
|||||||
|
|
||||||
const telegramBtn = ref(null)
|
const telegramBtn = ref(null)
|
||||||
|
|
||||||
function onTelegramAuth(user) {
|
async function onTelegramAuth(user) {
|
||||||
console.log('TG login success', user)
|
console.log('TG login success', user)
|
||||||
alert(`Logged in as ${user.first_name} (@${user.username})`)
|
alert(`Logged in as ${user.first_name} (@${user.username})`)
|
||||||
// 👉 здесь отправляешь user.auth_data на бэк для проверки Telegram-sign
|
// 👉 здесь отправляешь user.auth_data на бэк для проверки Telegram-sign
|
||||||
|
await userStore.tgLogin(user.id, user.first_name, user.last_name, user.username, user.photo_url, user.auth_date, user.hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
|
|
||||||
// передаём функцию глобально чтобы виджет её увидел
|
// передаём функцию глобально чтобы виджет её увидел
|
||||||
window.onTelegramAuth = onTelegramAuth
|
window.onTelegramAuth = onTelegramAuth
|
||||||
@@ -44,8 +45,8 @@ onMounted(() => {
|
|||||||
if (tgApp.initData) {
|
if (tgApp.initData) {
|
||||||
tgData.value = tgApp.initDataUnsafe
|
tgData.value = tgApp.initDataUnsafe
|
||||||
if (tgData.value.user?.id != null) {
|
if (tgData.value.user?.id != null) {
|
||||||
localStorage.setItem("token", tgData.value.user.id.toString())
|
let user = tgData.value.user
|
||||||
router.push("/")
|
await userStore.tgLogin(user.id, user.first_name, user.last_name, user.username, user.photo_url, user.auth_date, user.hash)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -58,38 +59,38 @@ onMounted(() => {
|
|||||||
<div class="login">
|
<div class="login">
|
||||||
<div ref="telegramBtn"></div>
|
<div ref="telegramBtn"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex !w-full items-center justify-center h-100">
|
<!-- <div class="flex !w-full items-center justify-center h-100">-->
|
||||||
<div class="card !w-fit">
|
<!-- <div class="card !w-fit">-->
|
||||||
|
|
||||||
<h1 class="text-2xl font-bold text-center">Вход</h1>
|
<!-- <h1 class="text-2xl font-bold text-center">Вход</h1>-->
|
||||||
|
|
||||||
|
|
||||||
<form @submit.prevent="userStore.login(username, password)" class="flex flex-col !gap-6 !w-fit !p-10">
|
<!-- <form @submit.prevent="userStore.login(username, password)" class="flex flex-col !gap-6 !w-fit !p-10">-->
|
||||||
<div class="!w-full">
|
<!-- <div class="!w-full">-->
|
||||||
<label for="username" class="block text-sm font-semibold text-gray-700">Логин</label>
|
<!-- <label for="username" class="block text-sm font-semibold text-gray-700">Логин</label>-->
|
||||||
<InputText id="username" v-model.trim="username" class="w-full" :class="{'p-invalid': errors.username}"/>
|
<!-- <InputText id="username" v-model.trim="username" class="w-full" :class="{'p-invalid': errors.username}"/>-->
|
||||||
<small v-if="errors.username" class="text-red-500">{{ errors.username }}</small>
|
<!-- <small v-if="errors.username" class="text-red-500">{{ errors.username }}</small>-->
|
||||||
</div>
|
<!-- </div>-->
|
||||||
|
|
||||||
<div class="mb-6">
|
<!-- <div class="mb-6">-->
|
||||||
<label for="password" class="block text-sm font-semibold text-gray-700">Пароль</label>
|
<!-- <label for="password" class="block text-sm font-semibold text-gray-700">Пароль</label>-->
|
||||||
<Password id="password" v-model="password" class="w-full" :feedback="false" toggleMask/>
|
<!-- <Password id="password" v-model="password" class="w-full" :feedback="false" toggleMask/>-->
|
||||||
<small v-if="errors.password" class="text-red-500">{{ errors.password }}</small>
|
<!-- <small v-if="errors.password" class="text-red-500">{{ errors.password }}</small>-->
|
||||||
</div>
|
<!-- </div>-->
|
||||||
|
|
||||||
<Button label="Войти" type="submit" class="w-full mt-2 !bg-blue-300 hover:!bg-blue-400 !border-blue-300"
|
<!-- <Button label="Войти" type="submit" class="w-full mt-2 !bg-blue-300 hover:!bg-blue-400 !border-blue-300"-->
|
||||||
:disabled="loading" :loading="loading"/>
|
<!-- :disabled="loading" :loading="loading"/>-->
|
||||||
</form>
|
<!-- </form>-->
|
||||||
|
|
||||||
|
|
||||||
<p class="mt-4 text-sm text-center text-gray-600">
|
<!-- <p class="mt-4 text-sm text-center text-gray-600">-->
|
||||||
Нет аккаунта?
|
<!-- Нет аккаунта?-->
|
||||||
<RouterLink to="/register" class="text-blue-500 hover:underline">Регистрация</RouterLink>
|
<!-- <RouterLink to="/register" class="text-blue-500 hover:underline">Регистрация</RouterLink>-->
|
||||||
</p>
|
<!-- </p>-->
|
||||||
|
|
||||||
|
|
||||||
</div>
|
<!-- </div>-->
|
||||||
</div>
|
<!-- </div>-->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {defineStore} from 'pinia';
|
import {defineStore} from 'pinia';
|
||||||
import {computed, ref} from 'vue';
|
import {ref} from 'vue';
|
||||||
import apiClient from "@/network/axiosSetup";
|
import apiClient from "@/network/axiosSetup";
|
||||||
import {useRoute, useRouter} from "vue-router";
|
import {useRoute, useRouter} from "vue-router";
|
||||||
import {useToast} from "primevue/usetoast";
|
import {useToast} from "primevue/usetoast";
|
||||||
@@ -36,6 +36,39 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function tgLogin(id: number, first_name: string, last_name: string, username: string, photo_url: string, auth_date: string, hash: string) {
|
||||||
|
try {
|
||||||
|
let response;
|
||||||
|
|
||||||
|
response = await apiClient.post('/auth/tg-login', {
|
||||||
|
id: id,
|
||||||
|
first_name: first_name,
|
||||||
|
last_name: last_name,
|
||||||
|
username: username,
|
||||||
|
photo_url: photo_url,
|
||||||
|
auth_date: auth_date,
|
||||||
|
hash: hash,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const token = response.data.token;
|
||||||
|
console.log(token);
|
||||||
|
localStorage.setItem('token', token);
|
||||||
|
apiClient.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
||||||
|
toast.add({severity: 'success', summary: 'Вход выполнен', detail: 'Добро пожаловать!', life: 3000})
|
||||||
|
await fetchUserProfile();
|
||||||
|
await router.push(route.query['back'] ? route.query['back'].toString() : '/');
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(error);
|
||||||
|
toast.add({
|
||||||
|
severity: 'error',
|
||||||
|
summary: 'Ошибка авторизации',
|
||||||
|
detail: error.response.data.message,
|
||||||
|
life: 3000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Основная функция для логина
|
// Основная функция для логина
|
||||||
async function login(username: string, password: string) {
|
async function login(username: string, password: string) {
|
||||||
|
|
||||||
@@ -81,5 +114,5 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return {user, loadingUser, fetchUserProfile, login, register, isAuthorized};
|
return {user, loadingUser, fetchUserProfile, tgLogin, register, isAuthorized};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user