Compare commits
14 Commits
pagina-log
...
7bf152e93b
| Author | SHA1 | Date | |
|---|---|---|---|
| 7bf152e93b | |||
| 977ff6ed20 | |||
| ac51e11f33 | |||
| 20a4a14a4a | |||
| d1e9b58213 | |||
| 5a4917c4a1 | |||
| 6a17151bef | |||
| 2c06753e81 | |||
| 0dd0716b7c | |||
| ef9fef66b8 | |||
| 5fb43e0087 | |||
| c1ad6b4cfe | |||
| 7153caa0ac | |||
| 7652c8aad5 |
@@ -3,7 +3,7 @@ DATABASE_URL="postgresql://postgres:postgres@localhost:5432/sistema_auth?schema=
|
|||||||
DIRECT_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/sistema_auth?schema=public"
|
DIRECT_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/sistema_auth?schema=public"
|
||||||
|
|
||||||
# JWT contract
|
# JWT contract
|
||||||
JWT_ISSUER="https://auth.local"
|
JWT_ISSUER="https://sistema-distribuido-trabalho-faculd.vercel.app"
|
||||||
JWT_AUDIENCE="internal-apis"
|
JWT_AUDIENCE="internal-apis"
|
||||||
JWT_ACCESS_TTL_SEC="900"
|
JWT_ACCESS_TTL_SEC="900"
|
||||||
JWT_REFRESH_TTL_SEC="604800"
|
JWT_REFRESH_TTL_SEC="604800"
|
||||||
@@ -15,3 +15,4 @@ JWT_PUBLIC_KEY_PEM="<replace-with-escaped-pem>"
|
|||||||
REFRESH_TOKEN_PEPPER="change-me"
|
REFRESH_TOKEN_PEPPER="change-me"
|
||||||
PASSWORD_RESET_TTL_SEC="900"
|
PASSWORD_RESET_TTL_SEC="900"
|
||||||
PASSWORD_RESET_TOKEN_PEPPER="change-me"
|
PASSWORD_RESET_TOKEN_PEPPER="change-me"
|
||||||
|
PASSWORD_RESET_BASE_URL="http://localhost:3000"
|
||||||
|
|||||||
51
app/components/AppSelect.vue
Normal file
51
app/components/AppSelect.vue
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<template>
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<label :for="id" class="m-0 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169]">
|
||||||
|
{{ label }}
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="relative">
|
||||||
|
<select :id="id" v-model="selectedValue" :disabled="disabled"
|
||||||
|
class="h-14 w-full appearance-none rounded-lg border border-[#d6d3d1] bg-white px-4 pr-11 text-base leading-normal tracking-[0.16px] text-[#0c0a09] outline-none transition focus:border-2 focus:border-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-50">
|
||||||
|
<option v-for="option in options" :key="option.value" :value="option.value">
|
||||||
|
{{ option.label }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<Icon name="mdi:chevron-down"
|
||||||
|
class="pointer-events-none absolute right-4 top-1/2 -translate-y-1/2 text-xl text-[#777169]" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
const props = defineProps({
|
||||||
|
id: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
modelValue: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
type: Array,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits(['update:modelValue'])
|
||||||
|
|
||||||
|
const selectedValue = computed({
|
||||||
|
get: () => props.modelValue,
|
||||||
|
set: (value) => emit('update:modelValue', value)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
146
app/pages/(auth)/auth/reset-password/index.vue
Normal file
146
app/pages/(auth)/auth/reset-password/index.vue
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="relative grid min-h-screen place-items-center overflow-hidden bg-[#f5f5f5] px-4 py-12 font-sans text-[#0c0a09] md:py-24">
|
||||||
|
<div
|
||||||
|
class="pointer-events-none absolute left-1/2 top-10 h-[420px] w-[min(92vw,760px)] -translate-x-1/2 rounded-[48px] bg-[radial-gradient(circle_at_20%_30%,rgba(232,184,196,0.58),transparent_28%),radial-gradient(circle_at_72%_24%,rgba(167,229,211,0.56),transparent_30%),radial-gradient(circle_at_52%_78%,rgba(244,197,168,0.5),transparent_34%)] blur-2xl"
|
||||||
|
aria-hidden="true"></div>
|
||||||
|
|
||||||
|
<main
|
||||||
|
class="relative grid w-full max-w-[1120px] grid-cols-1 items-center gap-8 md:grid-cols-[minmax(0,1fr)_minmax(340px,440px)] md:gap-16"
|
||||||
|
aria-labelledby="reset-password-title">
|
||||||
|
<section class="relative pt-2 md:py-8">
|
||||||
|
<p
|
||||||
|
class="m-0 inline-flex rounded-full bg-[rgba(232,184,196,0.58)] px-3 py-1 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#0c0a09]">
|
||||||
|
Nova senha
|
||||||
|
</p>
|
||||||
|
<h1 id="reset-password-title"
|
||||||
|
class="my-5 max-w-[640px] font-serif text-[40px] font-light leading-[1.05] tracking-[-1.2px] text-[#0c0a09] md:text-[64px] md:tracking-[-1.92px]">
|
||||||
|
Redefina sua senha
|
||||||
|
</h1>
|
||||||
|
<p class="m-0 max-w-[520px] text-base font-normal leading-6 tracking-[0.16px] text-[#4e4e4e]">
|
||||||
|
Use o token gerado na recuperação para definir uma nova senha de acesso.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section
|
||||||
|
class="grid gap-5 rounded-2xl border border-[#e7e5e4] bg-white p-6 shadow-[0_4px_16px_rgba(0,0,0,0.04)] md:p-8"
|
||||||
|
aria-label="Formulario de redefinicao de senha">
|
||||||
|
<div class="mb-1">
|
||||||
|
<span
|
||||||
|
class="inline-flex min-h-6 items-center rounded-full bg-[rgba(232,184,196,0.58)] px-2.5 py-1 text-xs font-semibold uppercase leading-none tracking-[0.96px] text-[#0c0a09]">
|
||||||
|
Reset
|
||||||
|
</span>
|
||||||
|
<h2 class="mt-4 font-serif text-3xl font-light leading-[1.13] tracking-[-0.32px] text-[#0c0a09]">
|
||||||
|
Dados da nova senha
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Form :validation-schema="schema" :initial-values="initialValues" @submit="redefinirSenha" class="grid gap-5">
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<label class="m-0 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169]"
|
||||||
|
for="new-password">
|
||||||
|
Nova senha
|
||||||
|
</label>
|
||||||
|
<Field name="newPassword" v-slot="{ field, meta }">
|
||||||
|
<input v-bind="field" :disabled="isLoading"
|
||||||
|
class="h-11 w-full rounded-lg border bg-white px-4 py-3 text-base leading-6 tracking-[0.16px] text-[#0c0a09] outline-none transition focus:border-2 focus:border-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
:class="meta.touched && !meta.valid ? 'border-red-400' : 'border-[#d6d3d1]'" type="password"
|
||||||
|
id="new-password" />
|
||||||
|
</Field>
|
||||||
|
<ErrorMessage name="newPassword" class="text-xs text-red-500" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<label class="m-0 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169]"
|
||||||
|
for="confirm-password">
|
||||||
|
Confirmar senha
|
||||||
|
</label>
|
||||||
|
<Field name="confirmPassword" v-slot="{ field, meta }">
|
||||||
|
<input v-bind="field" :disabled="isLoading"
|
||||||
|
class="h-11 w-full rounded-lg border bg-white px-4 py-3 text-base leading-6 tracking-[0.16px] text-[#0c0a09] outline-none transition focus:border-2 focus:border-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
:class="meta.touched && !meta.valid ? 'border-red-400' : 'border-[#d6d3d1]'" type="password"
|
||||||
|
id="confirm-password" />
|
||||||
|
</Field>
|
||||||
|
<ErrorMessage name="confirmPassword" class="text-xs text-red-500" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-if="!resetToken"
|
||||||
|
class="rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm leading-[1.47] text-red-600">
|
||||||
|
Link de recuperação inválido. Gere uma nova recuperação de senha.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<button type="submit" :disabled="isLoading || !resetToken"
|
||||||
|
class="mt-1 inline-flex h-10 items-center justify-center gap-2 rounded-full bg-[#292524] px-5 text-[15px] font-medium leading-none text-white transition hover:bg-[#0c0a09] active:bg-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-70">
|
||||||
|
<Icon v-if="isLoading" name="mdi:loading" class="animate-spin text-base" />
|
||||||
|
<span v-else>Redefinir senha</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<p class="text-center text-[15px] leading-[1.47] tracking-[0.15px] text-[#777169]">
|
||||||
|
Lembrou a sua senha?
|
||||||
|
<NuxtLink to="/login" class="font-medium text-[#0c0a09] underline-offset-2 hover:underline">
|
||||||
|
Entrar agora
|
||||||
|
</NuxtLink>
|
||||||
|
</p>
|
||||||
|
</Form>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { toTypedSchema } from '@vee-validate/zod'
|
||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
definePageMeta({ middleware: 'guest' })
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const { $toast } = useNuxtApp()
|
||||||
|
|
||||||
|
const isLoading = ref(false)
|
||||||
|
|
||||||
|
const toStr = (val) => (val == null ? '' : String(val))
|
||||||
|
const resetToken = computed(() => (typeof route.query.token === 'string' ? route.query.token : ''))
|
||||||
|
|
||||||
|
const initialValues = {
|
||||||
|
newPassword: '',
|
||||||
|
confirmPassword: ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const schema = toTypedSchema(
|
||||||
|
z
|
||||||
|
.object({
|
||||||
|
newPassword: z.preprocess(
|
||||||
|
toStr,
|
||||||
|
z.string().min(8, 'A senha deve ter no mínimo 8 caracteres')
|
||||||
|
),
|
||||||
|
confirmPassword: z.preprocess(toStr, z.string().min(1, 'Confirme a nova senha'))
|
||||||
|
})
|
||||||
|
.refine((data) => data.newPassword === data.confirmPassword, {
|
||||||
|
message: 'As senhas não conferem',
|
||||||
|
path: ['confirmPassword']
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
async function redefinirSenha({ newPassword }) {
|
||||||
|
isLoading.value = true
|
||||||
|
try {
|
||||||
|
await $fetch('/auth/reset-password', {
|
||||||
|
method: 'POST',
|
||||||
|
body: {
|
||||||
|
token: resetToken.value,
|
||||||
|
new_password: newPassword
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$toast.success('Senha redefinida com sucesso!', { duration: 8000 })
|
||||||
|
await navigateTo('/login')
|
||||||
|
} catch (error) {
|
||||||
|
const message = error?.data?.statusMessage
|
||||||
|
$toast.error(message ?? 'Erro ao redefinir senha. Gere um novo token e tente novamente.', {
|
||||||
|
duration: 8000
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,86 +1,88 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<div
|
||||||
|
class="relative grid min-h-screen place-items-center overflow-hidden bg-[#f5f5f5] px-4 py-12 font-sans text-[#0c0a09] md:py-24">
|
||||||
<div
|
<div
|
||||||
class="relative grid min-h-screen place-items-center overflow-hidden bg-[#f5f5f5] px-4 py-12 font-sans text-[#0c0a09] md:py-24">
|
class="pointer-events-none absolute left-1/2 top-10 h-[420px] w-[min(92vw,760px)] -translate-x-1/2 rounded-[48px] bg-[radial-gradient(circle_at_20%_30%,rgba(167,229,211,0.62),transparent_28%),radial-gradient(circle_at_72%_24%,rgba(244,197,168,0.56),transparent_30%),radial-gradient(circle_at_52%_78%,rgba(200,184,224,0.5),transparent_34%)] blur-2xl"
|
||||||
<div class="pointer-events-none absolute left-1/2 top-10 h-[420px] w-[min(92vw,760px)] -translate-x-1/2 rounded-[48px] bg-[radial-gradient(circle_at_20%_30%,rgba(167,229,211,0.62),transparent_28%),radial-gradient(circle_at_72%_24%,rgba(244,197,168,0.56),transparent_30%),radial-gradient(circle_at_52%_78%,rgba(200,184,224,0.5),transparent_34%)] blur-2xl"
|
aria-hidden="true"></div>
|
||||||
aria-hidden="true"></div>
|
<main
|
||||||
<main
|
class="relative grid w-full max-w-[1120px] grid-cols-1 items-center gap-8 md:grid-cols-[minmax(0,1fr)_minmax(340px,420px)] md:gap-16"
|
||||||
class="relative grid w-full max-w-[1120px] grid-cols-1 items-center gap-8 md:grid-cols-[minmax(0,1fr)_minmax(340px,420px)] md:gap-16"
|
aria-labelledby="create-account-title">
|
||||||
aria-labelledby="create-account-title">
|
<section class="relative pt-2 md:py-8">
|
||||||
<section class="relative pt-2 md:py-8">
|
<p
|
||||||
<p
|
class="m-0 inline-flex rounded-full bg-[rgba(200,184,224,0.5)] px-3 py-1 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#0c0a09]">
|
||||||
class="m-0 inline-flex rounded-full bg-[rgba(200,184,224,0.5)] px-3 py-1 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#0c0a09]">
|
Login
|
||||||
Login
|
</p>
|
||||||
</p>
|
<h1 id="create-account-title"
|
||||||
<h1 id="create-account-title"
|
class="my-5 max-w-[640px] font-serif text-[40px] font-light leading-[1.05] tracking-[-1.2px] text-[#0c0a09] md:text-[64px] md:tracking-[-1.92px]">
|
||||||
class="my-5 max-w-[640px] font-serif text-[40px] font-light leading-[1.05] tracking-[-1.2px] text-[#0c0a09] md:text-[64px] md:tracking-[-1.92px]">
|
Faça seu login
|
||||||
Faça seu login
|
</h1>
|
||||||
</h1>
|
<p class="m-0 max-w-[520px] text-base font-normal leading-6 tracking-[0.16px] text-[#4e4e4e]">
|
||||||
<p class="m-0 max-w-[520px] text-base font-normal leading-6 tracking-[0.16px] text-[#4e4e4e]">
|
Faça seu login com email e senha.
|
||||||
Faça seu login com email e senha.
|
</p>
|
||||||
</p>
|
</section>
|
||||||
</section>
|
|
||||||
|
|
||||||
<section
|
<section
|
||||||
class="grid gap-5 rounded-2xl border border-[#e7e5e4] bg-white p-6 shadow-[0_4px_16px_rgba(0,0,0,0.04)] md:p-8"
|
class="grid gap-5 rounded-2xl border border-[#e7e5e4] bg-white p-6 shadow-[0_4px_16px_rgba(0,0,0,0.04)] md:p-8"
|
||||||
aria-label="Formulario de criacao de conta">
|
aria-label="Formulario de criacao de conta">
|
||||||
<div class="mb-1">
|
<div class="mb-1">
|
||||||
<span
|
<span
|
||||||
class="inline-flex min-h-6 items-center rounded-full bg-[rgba(200,184,224,0.5)] px-2.5 py-1 text-xs font-semibold uppercase leading-none tracking-[0.96px] text-[#0c0a09]">
|
class="inline-flex min-h-6 items-center rounded-full bg-[rgba(200,184,224,0.5)] px-2.5 py-1 text-xs font-semibold uppercase leading-none tracking-[0.96px] text-[#0c0a09]">
|
||||||
Login
|
Login
|
||||||
</span>
|
</span>
|
||||||
<h2 class="mt-4 font-serif text-3xl font-light leading-[1.13] tracking-[-0.32px] text-[#0c0a09]">
|
<h2 class="mt-4 font-serif text-3xl font-light leading-[1.13] tracking-[-0.32px] text-[#0c0a09]">
|
||||||
Dados de entrada
|
Dados de entrada
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Form :validation-schema="schema" @submit="entrarConta" class="grid gap-5">
|
<Form :validation-schema="schema" @submit="entrarConta" class="grid gap-5">
|
||||||
<div class="grid gap-2">
|
<div class="grid gap-2">
|
||||||
<label
|
<label class="m-0 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169]"
|
||||||
class="m-0 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169]"
|
for="email">
|
||||||
for="email">
|
Email
|
||||||
Email
|
</label>
|
||||||
</label>
|
<Field name="email" v-slot="{ field, meta }">
|
||||||
<Field name="email" v-slot="{ field, meta }">
|
<input v-bind="field" :disabled="isLoading"
|
||||||
<input v-bind="field" :disabled="isLoading"
|
class="h-11 w-full rounded-lg border bg-white px-4 py-3 text-base leading-6 tracking-[0.16px] text-[#0c0a09] outline-none transition focus:border-2 focus:border-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
class="h-11 w-full rounded-lg border bg-white px-4 py-3 text-base leading-6 tracking-[0.16px] text-[#0c0a09] outline-none transition focus:border-2 focus:border-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-50"
|
:class="meta.touched && !meta.valid ? 'border-red-400' : 'border-[#d6d3d1]'" type="email" id="email" />
|
||||||
:class="meta.touched && !meta.valid ? 'border-red-400' : 'border-[#d6d3d1]'"
|
</Field>
|
||||||
type="email" id="email" />
|
<ErrorMessage name="email" class="text-xs text-red-500" />
|
||||||
</Field>
|
</div>
|
||||||
<ErrorMessage name="email" class="text-xs text-red-500" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid gap-2">
|
<div class="grid gap-2">
|
||||||
<label
|
<label class="m-0 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169]"
|
||||||
class="m-0 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169]"
|
for="senha">
|
||||||
for="senha">
|
Senha
|
||||||
Senha
|
</label>
|
||||||
</label>
|
<Field name="password" v-slot="{ field, meta }">
|
||||||
<Field name="password" v-slot="{ field, meta }">
|
<input v-bind="field" :disabled="isLoading"
|
||||||
<input v-bind="field" :disabled="isLoading"
|
class="h-11 w-full rounded-lg border bg-white px-4 py-3 text-base leading-6 tracking-[0.16px] text-[#0c0a09] outline-none transition focus:border-2 focus:border-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
class="h-11 w-full rounded-lg border bg-white px-4 py-3 text-base leading-6 tracking-[0.16px] text-[#0c0a09] outline-none transition focus:border-2 focus:border-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-50"
|
:class="meta.touched && !meta.valid ? 'border-red-400' : 'border-[#d6d3d1]'" type="password"
|
||||||
:class="meta.touched && !meta.valid ? 'border-red-400' : 'border-[#d6d3d1]'"
|
id="senha" />
|
||||||
type="password" id="senha" />
|
</Field>
|
||||||
</Field>
|
<ErrorMessage name="password" class="text-xs text-red-500" />
|
||||||
<ErrorMessage name="password" class="text-xs text-red-500" />
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit" :disabled="isLoading"
|
<NuxtLink to="/recuperar-senha"
|
||||||
class="mt-1 inline-flex h-10 items-center justify-center gap-2 rounded-full bg-[#292524] px-5 text-[15px] font-medium leading-none text-white transition hover:bg-[#0c0a09] active:bg-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-70">
|
class="-mt-2 justify-self-end text-sm font-medium text-[#0c0a09] underline-offset-2 hover:underline">
|
||||||
<Icon v-if="isLoading" name="mdi:loading" class="animate-spin text-base" />
|
Esqueci minha senha
|
||||||
<span v-else>Entrar</span>
|
</NuxtLink>
|
||||||
</button>
|
|
||||||
|
|
||||||
<p class="text-center text-[15px] leading-[1.47] tracking-[0.15px] text-[#777169]">
|
<button type="submit" :disabled="isLoading"
|
||||||
Não tem uma conta?
|
class="mt-1 inline-flex h-10 items-center justify-center gap-2 rounded-full bg-[#292524] px-5 text-[15px] font-medium leading-none text-white transition hover:bg-[#0c0a09] active:bg-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-70">
|
||||||
<NuxtLink to="/criar-conta"
|
<Icon v-if="isLoading" name="mdi:loading" class="animate-spin text-base" />
|
||||||
class="font-medium text-[#0c0a09] underline-offset-2 hover:underline">
|
<span v-else>Entrar</span>
|
||||||
Criar conta
|
</button>
|
||||||
</NuxtLink>
|
|
||||||
</p>
|
<p class="text-center text-[15px] leading-[1.47] tracking-[0.15px] text-[#777169]">
|
||||||
</Form>
|
Não tem uma conta?
|
||||||
</section>
|
<NuxtLink to="/criar-conta" class="font-medium text-[#0c0a09] underline-offset-2 hover:underline">
|
||||||
</main>
|
Criar conta
|
||||||
</div>
|
</NuxtLink>
|
||||||
|
</p>
|
||||||
|
</Form>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@@ -92,9 +94,9 @@ definePageMeta({ middleware: 'guest' })
|
|||||||
const { $toast } = useNuxtApp()
|
const { $toast } = useNuxtApp()
|
||||||
|
|
||||||
const token = useCookie('token', {
|
const token = useCookie('token', {
|
||||||
secure: true,
|
secure: true,
|
||||||
sameSite: 'lax',
|
sameSite: 'lax',
|
||||||
maxAge: 900
|
maxAge: 900
|
||||||
})
|
})
|
||||||
|
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
@@ -102,32 +104,32 @@ const isLoading = ref(false)
|
|||||||
const toStr = (val) => (val == null ? '' : String(val))
|
const toStr = (val) => (val == null ? '' : String(val))
|
||||||
|
|
||||||
const schema = toTypedSchema(
|
const schema = toTypedSchema(
|
||||||
z.object({
|
z.object({
|
||||||
email: z.preprocess(toStr, z.string().min(1, 'Email é obrigatório').email('Email inválido')),
|
email: z.preprocess(toStr, z.string().min(1, 'Email é obrigatório').email('Email inválido')),
|
||||||
password: z.preprocess(toStr, z.string().min(1, 'A senha é obrigatória')),
|
password: z.preprocess(toStr, z.string().min(1, 'A senha é obrigatória'))
|
||||||
}),
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
async function entrarConta({ email, password }) {
|
async function entrarConta({ email, password }) {
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
try {
|
try {
|
||||||
const data = await $fetch('/auth/login', {
|
const data = await $fetch('/auth/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { email, password },
|
body: { email, password }
|
||||||
})
|
})
|
||||||
|
|
||||||
token.value = data.access_token
|
token.value = data.access_token
|
||||||
|
|
||||||
$toast.success('Login realizado com sucesso!', { duration: 8000 })
|
$toast.success('Login realizado com sucesso!', { duration: 8000 })
|
||||||
|
|
||||||
await navigateTo('/home')
|
await navigateTo('/home')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error?.data?.statusMessage
|
const message = error?.data?.statusMessage
|
||||||
$toast.error(message ?? 'Erro para efetuar o login. Tente novamente.', {
|
$toast.error(message ?? 'Erro para efetuar o login. Tente novamente.', {
|
||||||
duration: 8000,
|
duration: 8000
|
||||||
})
|
})
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
113
app/pages/(auth)/recuperar-senha/index.vue
Normal file
113
app/pages/(auth)/recuperar-senha/index.vue
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="relative grid min-h-screen place-items-center overflow-hidden bg-[#f5f5f5] px-4 py-12 font-sans text-[#0c0a09] md:py-24">
|
||||||
|
<div
|
||||||
|
class="pointer-events-none absolute left-1/2 top-10 h-[420px] w-[min(92vw,760px)] -translate-x-1/2 rounded-[48px] bg-[radial-gradient(circle_at_20%_30%,rgba(167,229,211,0.62),transparent_28%),radial-gradient(circle_at_72%_24%,rgba(168,200,232,0.56),transparent_30%),radial-gradient(circle_at_52%_78%,rgba(232,184,196,0.5),transparent_34%)] blur-2xl"
|
||||||
|
aria-hidden="true"></div>
|
||||||
|
|
||||||
|
<main
|
||||||
|
class="relative grid w-full max-w-[1120px] grid-cols-1 items-center gap-8 md:grid-cols-[minmax(0,1fr)_minmax(340px,440px)] md:gap-16"
|
||||||
|
aria-labelledby="recover-password-title">
|
||||||
|
<section class="relative pt-2 md:py-8">
|
||||||
|
<p
|
||||||
|
class="m-0 inline-flex rounded-full bg-[rgba(168,200,232,0.56)] px-3 py-1 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#0c0a09]">
|
||||||
|
Recuperação
|
||||||
|
</p>
|
||||||
|
<h1 id="recover-password-title"
|
||||||
|
class="my-5 max-w-[640px] font-serif text-[40px] font-light leading-[1.05] tracking-[-1.2px] text-[#0c0a09] md:text-[64px] md:tracking-[-1.92px]">
|
||||||
|
Recupere sua senha
|
||||||
|
</h1>
|
||||||
|
<p class="m-0 max-w-[520px] text-base font-normal leading-6 tracking-[0.16px] text-[#4e4e4e]">
|
||||||
|
Informe seu email para recuperar a sua senha.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section
|
||||||
|
class="grid gap-5 rounded-2xl border border-[#e7e5e4] bg-white p-6 shadow-[0_4px_16px_rgba(0,0,0,0.04)] md:p-8"
|
||||||
|
aria-label="Formulario de recuperacao de senha">
|
||||||
|
<div class="mb-1">
|
||||||
|
<span
|
||||||
|
class="inline-flex min-h-6 items-center rounded-full bg-[rgba(168,200,232,0.56)] px-2.5 py-1 text-xs font-semibold uppercase leading-none tracking-[0.96px] text-[#0c0a09]">
|
||||||
|
Senha
|
||||||
|
</span>
|
||||||
|
<h2 class="mt-4 font-serif text-3xl font-light leading-[1.13] tracking-[-0.32px] text-[#0c0a09]">
|
||||||
|
Email da conta
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Form :validation-schema="schema" @submit="solicitarRecuperacao" class="grid gap-5">
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<label class="m-0 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169]"
|
||||||
|
for="email">
|
||||||
|
Email
|
||||||
|
</label>
|
||||||
|
<Field name="email" v-slot="{ field, meta }">
|
||||||
|
<input v-bind="field" :disabled="isLoading"
|
||||||
|
class="h-11 w-full rounded-lg border bg-white px-4 py-3 text-base leading-6 tracking-[0.16px] text-[#0c0a09] outline-none transition focus:border-2 focus:border-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
:class="meta.touched && !meta.valid ? 'border-red-400' : 'border-[#d6d3d1]'" type="email" id="email" />
|
||||||
|
</Field>
|
||||||
|
<ErrorMessage name="email" class="text-xs text-red-500" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" :disabled="isLoading"
|
||||||
|
class="mt-1 inline-flex h-10 items-center justify-center gap-2 rounded-full bg-[#292524] px-5 text-[15px] font-medium leading-none text-white transition hover:bg-[#0c0a09] active:bg-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-70">
|
||||||
|
<Icon v-if="isLoading" name="mdi:loading" class="animate-spin text-base" />
|
||||||
|
<span v-else>Gerar recuperação</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<p class="text-center text-[15px] leading-[1.47] tracking-[0.15px] text-[#777169]">
|
||||||
|
Lembrou a senha?
|
||||||
|
<NuxtLink to="/login" class="font-medium text-[#0c0a09] underline-offset-2 hover:underline">
|
||||||
|
Fazer login
|
||||||
|
</NuxtLink>
|
||||||
|
</p>
|
||||||
|
</Form>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { toTypedSchema } from '@vee-validate/zod'
|
||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
definePageMeta({ middleware: 'guest' })
|
||||||
|
|
||||||
|
const { $toast } = useNuxtApp()
|
||||||
|
|
||||||
|
const isLoading = ref(false)
|
||||||
|
|
||||||
|
const toStr = (val) => (val == null ? '' : String(val))
|
||||||
|
|
||||||
|
const schema = toTypedSchema(
|
||||||
|
z.object({
|
||||||
|
email: z.preprocess(toStr, z.string().min(1, 'Email é obrigatório').email('Email inválido'))
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
async function solicitarRecuperacao({ email }) {
|
||||||
|
isLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = await $fetch('/auth/forgot-password', {
|
||||||
|
method: 'POST',
|
||||||
|
body: { email }
|
||||||
|
})
|
||||||
|
|
||||||
|
const resetUrl = data?.recovery?.reset_url
|
||||||
|
|
||||||
|
if (!resetUrl) {
|
||||||
|
throw new Error('Reset URL was not returned')
|
||||||
|
}
|
||||||
|
|
||||||
|
$toast.success('Recuperação gerada com sucesso!', { duration: 8000 })
|
||||||
|
await navigateTo(resetUrl, { external: true })
|
||||||
|
} catch (error) {
|
||||||
|
const message = error?.data?.statusMessage
|
||||||
|
$toast.error(message ?? 'Erro ao gerar recuperação de senha. Tente novamente.', {
|
||||||
|
duration: 8000
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
208
app/pages/(protected)/favoritos/index.vue
Normal file
208
app/pages/(protected)/favoritos/index.vue
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
<template>
|
||||||
|
<div class="relative min-h-screen overflow-hidden bg-[#f5f5f5] px-4 py-10 font-sans text-[#0c0a09] md:px-8 md:py-16">
|
||||||
|
<div
|
||||||
|
class="pointer-events-none absolute left-1/2 top-8 h-[460px] w-[min(92vw,820px)] -translate-x-1/2 rounded-[48px] bg-[radial-gradient(circle_at_20%_30%,rgba(232,184,196,0.6),transparent_28%),radial-gradient(circle_at_72%_24%,rgba(244,197,168,0.5),transparent_30%),radial-gradient(circle_at_52%_78%,rgba(168,200,232,0.56),transparent_34%)] blur-2xl"
|
||||||
|
aria-hidden="true"></div>
|
||||||
|
|
||||||
|
<main class="relative mx-auto grid w-full max-w-[1120px] gap-8" aria-labelledby="favoritos-title">
|
||||||
|
<header class="flex flex-col gap-5 sm:flex-row sm:items-end sm:justify-between">
|
||||||
|
<div>
|
||||||
|
<p
|
||||||
|
class="m-0 inline-flex rounded-full bg-[rgba(232,184,196,0.5)] px-3 py-1 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#0c0a09]">
|
||||||
|
Favoritos
|
||||||
|
</p>
|
||||||
|
<h1 id="favoritos-title"
|
||||||
|
class="my-5 max-w-[720px] font-serif text-[40px] font-light leading-[1.08] tracking-[-0.96px] text-[#0c0a09] md:text-[48px]">
|
||||||
|
Meus favoritos
|
||||||
|
</h1>
|
||||||
|
<p class="m-0 max-w-[560px] text-base font-normal leading-6 tracking-[0.16px] text-[#4e4e4e]">
|
||||||
|
Jogos que você salvou como favoritos. Gerencie sua lista aqui.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex gap-3">
|
||||||
|
<NuxtLink to="/ranking-jogos"
|
||||||
|
class="inline-flex h-10 items-center justify-center rounded-full border border-[#d6d3d1] bg-transparent px-5 text-[15px] font-medium leading-none text-[#0c0a09] transition hover:border-[#0c0a09]">
|
||||||
|
Ver rankings
|
||||||
|
</NuxtLink>
|
||||||
|
<NuxtLink to="/home"
|
||||||
|
class="inline-flex h-10 items-center justify-center rounded-full border border-[#d6d3d1] bg-transparent px-5 text-[15px] font-medium leading-none text-[#0c0a09] transition hover:border-[#0c0a09]">
|
||||||
|
Voltar
|
||||||
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section
|
||||||
|
class="grid gap-6 rounded-2xl border border-[#e7e5e4] bg-white p-6 shadow-[0_4px_16px_rgba(0,0,0,0.04)] md:p-8"
|
||||||
|
aria-label="Lista de jogos favoritos">
|
||||||
|
<div>
|
||||||
|
<span
|
||||||
|
class="inline-flex min-h-6 items-center rounded-full bg-[rgba(232,184,196,0.5)] px-2.5 py-1 text-xs font-semibold uppercase leading-none tracking-[0.96px] text-[#0c0a09]">
|
||||||
|
Salvos
|
||||||
|
</span>
|
||||||
|
<h2 class="mt-4 font-serif text-3xl font-light leading-[1.13] tracking-[-0.32px] text-[#0c0a09]">
|
||||||
|
Jogos favoritos
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="isLoading" class="grid gap-3" role="status" aria-live="polite">
|
||||||
|
<div v-for="item in 4" :key="item" class="h-16 animate-pulse rounded-xl bg-[#f0efed]"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="errorMessage"
|
||||||
|
class="rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-[15px] leading-[1.47] tracking-[0.15px] text-red-700"
|
||||||
|
role="alert">
|
||||||
|
{{ errorMessage }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="!favorites.length" class="rounded-xl border border-[#e7e5e4] bg-[#fafafa] px-4 py-8 text-center"
|
||||||
|
role="status">
|
||||||
|
<Icon name="mdi:heart-outline" class="mb-3 text-4xl text-[#d6d3d1]" />
|
||||||
|
<p class="text-[15px] leading-[1.47] tracking-[0.15px] text-[#777169]">
|
||||||
|
Nenhum jogo favorito ainda.<br />
|
||||||
|
<NuxtLink to="/ranking-jogos" class="underline hover:text-[#0c0a09]">Vá ao ranking</NuxtLink>
|
||||||
|
e adicione seus favoritos!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="overflow-hidden rounded-xl border border-[#e7e5e4]">
|
||||||
|
<div
|
||||||
|
class="hidden bg-[#fafafa] px-4 py-3 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169] md:grid md:grid-cols-[minmax(0,1fr)_160px] md:gap-4">
|
||||||
|
<span>Jogo</span>
|
||||||
|
<span>Ação</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="grid divide-y divide-[#e7e5e4]">
|
||||||
|
<li v-for="game in favorites" :key="game.id"
|
||||||
|
class="grid items-center gap-4 bg-white p-4 md:grid-cols-[minmax(0,1fr)_160px] md:gap-4">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<Icon name="mdi:heart" class="shrink-0 text-rose-500" />
|
||||||
|
<span class="text-base font-medium leading-6 tracking-[0.16px] text-[#0c0a09]">
|
||||||
|
{{ game.game_id }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="button" :disabled="removingId === game.game_id"
|
||||||
|
:aria-label="`Remover ${game.game_id} dos favoritos`" @click="removeFavorite(game)"
|
||||||
|
class="inline-flex h-9 items-center justify-center gap-2 rounded-full border border-[#e7e5e4] px-4 text-[13px] font-medium leading-none text-[#777169] transition hover:border-red-300 hover:text-red-600 disabled:cursor-not-allowed disabled:opacity-50">
|
||||||
|
<Icon :name="removingId === game.game_id ? 'mdi:loading' : 'mdi:heart-remove-outline'"
|
||||||
|
:class="['text-sm', removingId === game.game_id && 'animate-spin']" />
|
||||||
|
<span class="hidden sm:inline">{{ removingId === game.game_id ? 'Removendo...' : 'Remover' }}</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div class="flex flex-col items-center gap-2 text-center text-xs leading-[1.4] tracking-[0.16px] text-[#777169]">
|
||||||
|
<p>
|
||||||
|
Microsserviço consumido: <span class="font-medium text-[#4e4e4e]">https://gameverse-wishlist-production.up.railway.app</span>
|
||||||
|
· Feito por Edson
|
||||||
|
</p>
|
||||||
|
<span class="inline-flex items-center gap-1.5">
|
||||||
|
<span class="h-1.5 w-1.5 rounded-full bg-emerald-500"></span>
|
||||||
|
Sistema de validação de token funcional
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
definePageMeta({
|
||||||
|
middleware: 'auth'
|
||||||
|
})
|
||||||
|
|
||||||
|
const WISHLIST_API_BASE_URL = 'https://gameverse-wishlist-production.up.railway.app'
|
||||||
|
|
||||||
|
const { $toast } = useNuxtApp()
|
||||||
|
|
||||||
|
const token = useCookie('token', {
|
||||||
|
secure: true,
|
||||||
|
sameSite: 'lax',
|
||||||
|
maxAge: 900
|
||||||
|
})
|
||||||
|
|
||||||
|
const favorites = ref([])
|
||||||
|
const isLoading = ref(false)
|
||||||
|
const errorMessage = ref('')
|
||||||
|
const removingId = ref(null)
|
||||||
|
|
||||||
|
const clearToken = () => {
|
||||||
|
token.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchFavorites() {
|
||||||
|
if (!token.value) {
|
||||||
|
await navigateTo('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isLoading.value = true
|
||||||
|
errorMessage.value = ''
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await $fetch(`${WISHLIST_API_BASE_URL}/api/wishlist`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token.value}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
favorites.value = (data?.data ?? []).filter(
|
||||||
|
(item) => item.is_favorite === 1 || item.is_favorite === true
|
||||||
|
)
|
||||||
|
} catch (error) {
|
||||||
|
const statusCode = error?.statusCode ?? error?.response?.status ?? error?.data?.statusCode
|
||||||
|
|
||||||
|
if (statusCode === 401) {
|
||||||
|
clearToken()
|
||||||
|
$toast.error('Sua sessão expirou. Faça login novamente.', { duration: 8000 })
|
||||||
|
await navigateTo('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
errorMessage.value = error?.data?.message ?? 'Erro ao carregar os favoritos. Tente novamente.'
|
||||||
|
$toast.error(errorMessage.value, { duration: 8000 })
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeFavorite(game) {
|
||||||
|
if (!token.value) {
|
||||||
|
await navigateTo('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
removingId.value = game.game_id
|
||||||
|
|
||||||
|
try {
|
||||||
|
await $fetch(`${WISHLIST_API_BASE_URL}/api/wishlist/${encodeURIComponent(game.game_id)}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token.value}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
favorites.value = favorites.value.filter((f) => f.game_id !== game.game_id)
|
||||||
|
$toast.success(`${game.game_id} removido dos favoritos.`, { duration: 4000 })
|
||||||
|
} catch (error) {
|
||||||
|
const statusCode = error?.statusCode ?? error?.response?.status ?? error?.data?.statusCode
|
||||||
|
|
||||||
|
if (statusCode === 401) {
|
||||||
|
clearToken()
|
||||||
|
$toast.error('Sua sessão expirou. Faça login novamente.', { duration: 8000 })
|
||||||
|
await navigateTo('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$toast.error('Erro ao remover o favorito. Tente novamente.', { duration: 6000 })
|
||||||
|
} finally {
|
||||||
|
removingId.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fetchFavorites()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -1,11 +1,141 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div
|
||||||
<h1>OOOIII SOU A HOMEEE</h1>
|
class="relative min-h-screen overflow-hidden bg-[#f5f5f5] px-3 py-8 font-sans text-[#0c0a09] sm:px-5 sm:py-12 md:px-8 md:py-16">
|
||||||
</div>
|
<div
|
||||||
|
class="pointer-events-none absolute left-1/2 top-6 h-[360px] w-[min(94vw,760px)] -translate-x-1/2 rounded-[40px] bg-[radial-gradient(circle_at_20%_30%,rgba(167,229,211,0.62),transparent_28%),radial-gradient(circle_at_72%_24%,rgba(168,200,232,0.56),transparent_30%),radial-gradient(circle_at_52%_78%,rgba(232,184,196,0.5),transparent_34%)] blur-2xl sm:top-8 sm:h-[420px] sm:rounded-[48px]"
|
||||||
|
aria-hidden="true"></div>
|
||||||
|
|
||||||
|
<main class="relative mx-auto grid w-full max-w-[960px] gap-6 sm:gap-8" aria-labelledby="home-title">
|
||||||
|
<header class="flex min-w-0 flex-col gap-5 md:flex-row md:items-end md:justify-between">
|
||||||
|
<div class="min-w-0">
|
||||||
|
<p
|
||||||
|
class="m-0 inline-flex rounded-full bg-[rgba(168,200,232,0.56)] px-3 py-1 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#0c0a09]">
|
||||||
|
Conta
|
||||||
|
</p>
|
||||||
|
<h1 id="home-title"
|
||||||
|
class="my-4 max-w-[680px] break-words font-serif text-[34px] font-light leading-[1.08] tracking-[-0.96px] text-[#0c0a09] sm:my-5 sm:text-[40px] md:text-[48px]">
|
||||||
|
Olá, você está autenticado!
|
||||||
|
</h1>
|
||||||
|
<p
|
||||||
|
class="m-0 max-w-[540px] text-[15px] font-normal leading-[1.47] tracking-[0.15px] text-[#4e4e4e] sm:text-base sm:leading-6 sm:tracking-[0.16px]">
|
||||||
|
Estes são os dados retornados pelo perfil da sua sessão atual.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex shrink-0 flex-col items-start gap-3 sm:flex-row sm:items-center">
|
||||||
|
<NuxtLink to="/ranking-jogos"
|
||||||
|
class="inline-flex h-10 w-fit items-center justify-center rounded-full border border-[#d6d3d1] bg-transparent px-5 text-[15px] font-medium leading-none text-[#0c0a09] transition hover:border-[#0c0a09]">
|
||||||
|
Ver rankings
|
||||||
|
</NuxtLink>
|
||||||
|
<NuxtLink to="/favoritos"
|
||||||
|
class="inline-flex h-10 w-fit items-center justify-center rounded-full border border-[#d6d3d1] bg-transparent px-5 text-[15px] font-medium leading-none text-[#0c0a09] transition hover:border-[#0c0a09]">
|
||||||
|
Meus favoritos
|
||||||
|
</NuxtLink>
|
||||||
|
<button type="button" :disabled="isLeaving" @click="sair"
|
||||||
|
class="inline-flex h-10 w-fit items-center justify-center gap-2 rounded-full bg-[#292524] px-5 text-[15px] font-medium leading-none text-white transition hover:bg-[#0c0a09] active:bg-[#0c0a09] disabled:cursor-not-allowed disabled:opacity-70">
|
||||||
|
<Icon v-if="isLeaving" name="mdi:loading" class="animate-spin text-base" />
|
||||||
|
<span v-else>Sair</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section
|
||||||
|
class="grid min-w-0 gap-5 rounded-xl border border-[#e7e5e4] bg-white p-4 shadow-[0_4px_16px_rgba(0,0,0,0.04)] sm:rounded-2xl sm:p-6 md:p-8"
|
||||||
|
aria-label="Dados do perfil autenticado">
|
||||||
|
<div>
|
||||||
|
<span
|
||||||
|
class="inline-flex min-h-6 items-center rounded-full bg-[rgba(167,229,211,0.62)] px-2.5 py-1 text-xs font-semibold uppercase leading-none tracking-[0.96px] text-[#0c0a09]">
|
||||||
|
Perfil
|
||||||
|
</span>
|
||||||
|
<h2
|
||||||
|
class="mt-4 font-serif text-[26px] font-light leading-[1.13] tracking-[-0.32px] text-[#0c0a09] sm:text-3xl">
|
||||||
|
Dados da conta
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dl class="grid min-w-0 gap-3 sm:gap-4">
|
||||||
|
<div v-for="item in profileRows" :key="item.label"
|
||||||
|
class="grid min-w-0 gap-1 border-t border-[#e7e5e4] pt-3 sm:grid-cols-[140px_minmax(0,1fr)] sm:gap-5 sm:pt-4 md:grid-cols-[160px_minmax(0,1fr)]">
|
||||||
|
<dt class="text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169]">
|
||||||
|
{{ item.label }}
|
||||||
|
</dt>
|
||||||
|
<dd
|
||||||
|
class="m-0 min-w-0 text-[15px] leading-[1.47] tracking-[0.15px] text-[#0c0a09] sm:text-base sm:leading-6 sm:tracking-[0.16px]"
|
||||||
|
:class="item.isLong ? 'break-all' : 'break-words'">
|
||||||
|
{{ item.value }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
middleware: 'auth'
|
middleware: 'auth'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { $toast } = useNuxtApp()
|
||||||
|
|
||||||
|
const token = useCookie('token', {
|
||||||
|
secure: true,
|
||||||
|
sameSite: 'lax',
|
||||||
|
maxAge: 900
|
||||||
|
})
|
||||||
|
|
||||||
|
const isLeaving = ref(false)
|
||||||
|
|
||||||
|
const clearToken = () => {
|
||||||
|
token.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: profile, error } = await useAsyncData('profile-me', () =>
|
||||||
|
$fetch('/profile/me', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token.value}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
if (error.value) {
|
||||||
|
clearToken()
|
||||||
|
|
||||||
|
if (import.meta.client) {
|
||||||
|
$toast.error('Sua sessão expirou. Faça login novamente.', { duration: 8000 })
|
||||||
|
}
|
||||||
|
|
||||||
|
await navigateTo('/login')
|
||||||
|
}
|
||||||
|
|
||||||
|
const profileRows = computed(() => [
|
||||||
|
{
|
||||||
|
label: 'user_id',
|
||||||
|
value: profile.value?.user_id ?? profile.value?.id ?? '-'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'email',
|
||||||
|
value: profile.value?.email ?? '-'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'created_at',
|
||||||
|
value: profile.value?.created_at ?? '-'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'updated_at',
|
||||||
|
value: profile.value?.updated_at ?? '-'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'jwt_token',
|
||||||
|
value: token.value ?? '-',
|
||||||
|
isLong: true
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
async function sair() {
|
||||||
|
isLeaving.value = true
|
||||||
|
clearToken()
|
||||||
|
$toast.success('Sessão encerrada com sucesso.', { duration: 8000 })
|
||||||
|
await navigateTo('/login')
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
376
app/pages/(protected)/ranking-jogos/index.vue
Normal file
376
app/pages/(protected)/ranking-jogos/index.vue
Normal file
@@ -0,0 +1,376 @@
|
|||||||
|
<template>
|
||||||
|
<div class="relative min-h-screen overflow-hidden bg-[#f5f5f5] px-4 py-10 font-sans text-[#0c0a09] md:px-8 md:py-16">
|
||||||
|
<div
|
||||||
|
class="pointer-events-none absolute left-1/2 top-8 h-[460px] w-[min(92vw,820px)] -translate-x-1/2 rounded-[48px] bg-[radial-gradient(circle_at_20%_30%,rgba(167,229,211,0.62),transparent_28%),radial-gradient(circle_at_72%_24%,rgba(244,197,168,0.5),transparent_30%),radial-gradient(circle_at_52%_78%,rgba(168,200,232,0.56),transparent_34%)] blur-2xl"
|
||||||
|
aria-hidden="true"></div>
|
||||||
|
|
||||||
|
<main class="relative mx-auto grid w-full max-w-[1120px] gap-8" aria-labelledby="ranking-title">
|
||||||
|
<header class="flex flex-col gap-5 sm:flex-row sm:items-end sm:justify-between">
|
||||||
|
<div>
|
||||||
|
<p
|
||||||
|
class="m-0 inline-flex rounded-full bg-[rgba(244,197,168,0.56)] px-3 py-1 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#0c0a09]">
|
||||||
|
Rankings
|
||||||
|
</p>
|
||||||
|
<h1 id="ranking-title"
|
||||||
|
class="my-5 max-w-[720px] font-serif text-[40px] font-light leading-[1.08] tracking-[-0.96px] text-[#0c0a09] md:text-[48px]">
|
||||||
|
Ranking de jogos
|
||||||
|
</h1>
|
||||||
|
<p class="m-0 max-w-[560px] text-base font-normal leading-6 tracking-[0.16px] text-[#4e4e4e]">
|
||||||
|
Acompanhe os jogos por período, plataforma e volume de jogadores ativos.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<NuxtLink to="/home"
|
||||||
|
class="inline-flex h-10 items-center justify-center rounded-full border border-[#d6d3d1] bg-transparent px-5 text-[15px] font-medium leading-none text-[#0c0a09] transition hover:border-[#0c0a09]">
|
||||||
|
Voltar
|
||||||
|
</NuxtLink>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section
|
||||||
|
class="grid gap-6 rounded-2xl border border-[#e7e5e4] bg-white p-6 shadow-[0_4px_16px_rgba(0,0,0,0.04)] md:p-8"
|
||||||
|
aria-label="Lista de ranking de jogos">
|
||||||
|
<div class="grid gap-5 md:grid-cols-[minmax(0,1fr)_minmax(240px,320px)] md:items-end">
|
||||||
|
<div>
|
||||||
|
<span
|
||||||
|
class="inline-flex min-h-6 items-center rounded-full bg-[rgba(167,229,211,0.62)] px-2.5 py-1 text-xs font-semibold uppercase leading-none tracking-[0.96px] text-[#0c0a09]">
|
||||||
|
{{ selectedRankingMeta.badge }}
|
||||||
|
</span>
|
||||||
|
<h2 class="mt-4 font-serif text-3xl font-light leading-[1.13] tracking-[-0.32px] text-[#0c0a09]">
|
||||||
|
{{ selectedRankingMeta.title }}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<AppSelect id="ranking-filter" v-model="selectedRanking" label="Visualização" :options="rankingOptions"
|
||||||
|
:disabled="isLoading" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="isLoading" class="grid gap-3" role="status" aria-live="polite">
|
||||||
|
<div v-for="item in 4" :key="item" class="h-20 animate-pulse rounded-xl bg-[#f0efed]"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="errorMessage"
|
||||||
|
class="rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-[15px] leading-[1.47] tracking-[0.15px] text-red-700"
|
||||||
|
role="alert">
|
||||||
|
{{ errorMessage }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="!rankings.length"
|
||||||
|
class="rounded-xl border border-[#e7e5e4] bg-[#fafafa] px-4 py-6 text-center text-[15px] leading-[1.47] tracking-[0.15px] text-[#777169]">
|
||||||
|
Nenhum jogo encontrado para este ranking.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="overflow-hidden rounded-xl border border-[#e7e5e4]">
|
||||||
|
<div
|
||||||
|
class="hidden bg-[#fafafa] px-4 py-3 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169] md:grid md:grid-cols-[72px_minmax(180px,1.5fr)_minmax(130px,1fr)_repeat(4,minmax(100px,1fr))] md:gap-4">
|
||||||
|
<span>Posição</span>
|
||||||
|
<span>Jogo</span>
|
||||||
|
<span>Plataforma</span>
|
||||||
|
<span>Jogadores</span>
|
||||||
|
<span>Semanal</span>
|
||||||
|
<span>Mensal</span>
|
||||||
|
<span>Anual</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ol class="grid divide-y divide-[#e7e5e4]">
|
||||||
|
<li v-for="(game, index) in rankings" :key="game.id"
|
||||||
|
class="grid gap-4 bg-white p-4 md:grid-cols-[72px_minmax(180px,1.5fr)_minmax(130px,1fr)_repeat(4,minmax(100px,1fr))] md:items-center md:gap-4">
|
||||||
|
<div class="flex items-center justify-between gap-3 md:block">
|
||||||
|
<span class="text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169] md:hidden">
|
||||||
|
Posição
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="inline-flex h-9 min-w-9 items-center justify-center rounded-full bg-[#292524] px-3 text-[15px] font-medium leading-none text-white">
|
||||||
|
{{ index + 1 }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-1">
|
||||||
|
<span class="text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169] md:hidden">
|
||||||
|
Jogo
|
||||||
|
</span>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<strong class="text-base font-medium leading-6 tracking-[0.16px] text-[#0c0a09]">
|
||||||
|
{{ game.name }}
|
||||||
|
</strong>
|
||||||
|
<button type="button" :disabled="togglingId === game.name"
|
||||||
|
:aria-label="favoriteIds.has(game.name) ? 'Remover dos favoritos' : 'Adicionar aos favoritos'"
|
||||||
|
@click="toggleFavorite(game)"
|
||||||
|
class="inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition hover:bg-[#f0efed] disabled:cursor-not-allowed disabled:opacity-50">
|
||||||
|
<Icon
|
||||||
|
:name="togglingId === game.name ? 'mdi:loading' : favoriteIds.has(game.name) ? 'mdi:heart' : 'mdi:heart-outline'"
|
||||||
|
:class="['text-base', togglingId === game.name ? 'animate-spin text-[#777169]' : favoriteIds.has(game.name) ? 'text-rose-500' : 'text-[#777169]']" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-for="stat in getGameStats(game)" :key="stat.label"
|
||||||
|
class="flex items-center justify-between gap-3 md:block">
|
||||||
|
<span class="text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#777169] md:hidden">
|
||||||
|
{{ stat.label }}
|
||||||
|
</span>
|
||||||
|
<span class="text-[15px] leading-[1.47] tracking-[0.15px] text-[#292524]">
|
||||||
|
{{ stat.value }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div class="flex flex-col items-center gap-2 text-center text-xs leading-[1.4] tracking-[0.16px] text-[#777169]">
|
||||||
|
<p>
|
||||||
|
Microsserviço consumido: <span
|
||||||
|
class="font-medium text-[#4e4e4e]">https://api-ranking-jogos-production.up.railway.app/api/v1</span>
|
||||||
|
· Feito por Gabriel e Kaiky
|
||||||
|
</p>
|
||||||
|
<span class="inline-flex items-center gap-1.5">
|
||||||
|
<span class="h-1.5 w-1.5 rounded-full bg-emerald-500"></span>
|
||||||
|
Sistema de validação de token funcional
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
definePageMeta({
|
||||||
|
middleware: 'auth'
|
||||||
|
})
|
||||||
|
|
||||||
|
const RANKINGS_API_BASE_URL = 'https://api-ranking-jogos-production.up.railway.app/api/v1'
|
||||||
|
const WISHLIST_API_BASE_URL = 'https://gameverse-wishlist-production.up.railway.app'
|
||||||
|
|
||||||
|
const rankingOptions = [
|
||||||
|
{
|
||||||
|
label: 'Semanal',
|
||||||
|
value: 'weekly',
|
||||||
|
endpoint: '/rankings/weekly',
|
||||||
|
badge: 'Semana',
|
||||||
|
title: 'Ranking semanal'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Mensal',
|
||||||
|
value: 'monthly',
|
||||||
|
endpoint: '/rankings/monthly',
|
||||||
|
badge: 'Mês',
|
||||||
|
title: 'Ranking mensal'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Anual',
|
||||||
|
value: 'yearly',
|
||||||
|
endpoint: '/rankings/yearly',
|
||||||
|
badge: 'Ano',
|
||||||
|
title: 'Ranking anual'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Steam',
|
||||||
|
value: 'steam',
|
||||||
|
endpoint: '/rankings/platforms/Steam',
|
||||||
|
badge: 'Steam',
|
||||||
|
title: 'Ranking da Steam'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Epic Games',
|
||||||
|
value: 'epic-games',
|
||||||
|
endpoint: '/rankings/platforms/Epic Games',
|
||||||
|
badge: 'Epic Games',
|
||||||
|
title: 'Ranking da Epic Games'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Riot Launcher',
|
||||||
|
value: 'riot-launcher',
|
||||||
|
endpoint: '/rankings/platforms/Riot Launcher',
|
||||||
|
badge: 'Riot Launcher',
|
||||||
|
title: 'Ranking da Riot Launcher'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Multiplataforma',
|
||||||
|
value: 'multi-platform',
|
||||||
|
endpoint: '/rankings/platforms/Multiplataforma',
|
||||||
|
badge: 'Multiplataforma',
|
||||||
|
title: 'Ranking multiplataforma'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Battle.net',
|
||||||
|
value: 'battle-net',
|
||||||
|
endpoint: '/rankings/platforms/Battle.net',
|
||||||
|
badge: 'Battle.net',
|
||||||
|
title: 'Ranking da Battle.net'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Mais jogados',
|
||||||
|
value: 'most-played',
|
||||||
|
endpoint: '/games/most-played',
|
||||||
|
badge: 'Ativos',
|
||||||
|
title: 'Jogos mais jogados'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const { $toast } = useNuxtApp()
|
||||||
|
|
||||||
|
const token = useCookie('token', {
|
||||||
|
secure: true,
|
||||||
|
sameSite: 'lax',
|
||||||
|
maxAge: 900
|
||||||
|
})
|
||||||
|
|
||||||
|
const selectedRanking = ref('weekly')
|
||||||
|
const rankings = ref([])
|
||||||
|
const isLoading = ref(false)
|
||||||
|
const errorMessage = ref('')
|
||||||
|
const favoriteIds = ref(new Set())
|
||||||
|
const togglingId = ref(null)
|
||||||
|
|
||||||
|
const selectedRankingMeta = computed(() => {
|
||||||
|
return rankingOptions.find((option) => option.value === selectedRanking.value) ?? rankingOptions[0]
|
||||||
|
})
|
||||||
|
|
||||||
|
const clearToken = () => {
|
||||||
|
token.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatNumber = (value) => {
|
||||||
|
return new Intl.NumberFormat('pt-BR').format(Number(value ?? 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
const getGameStats = (game) => [
|
||||||
|
{
|
||||||
|
label: 'Plataforma',
|
||||||
|
value: game.platform
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Jogadores',
|
||||||
|
value: formatNumber(game.active_players)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Semanal',
|
||||||
|
value: formatNumber(game.weekly_points)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Mensal',
|
||||||
|
value: formatNumber(game.monthly_points)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Anual',
|
||||||
|
value: formatNumber(game.yearly_points)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
async function fetchRankings() {
|
||||||
|
if (!token.value) {
|
||||||
|
await navigateTo('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isLoading.value = true
|
||||||
|
errorMessage.value = ''
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await $fetch(`${RANKINGS_API_BASE_URL}${selectedRankingMeta.value.endpoint}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token.value}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
rankings.value = Array.isArray(data) ? data : []
|
||||||
|
} catch (error) {
|
||||||
|
const statusCode = error?.statusCode ?? error?.response?.status ?? error?.data?.statusCode
|
||||||
|
|
||||||
|
if (statusCode === 401) {
|
||||||
|
clearToken()
|
||||||
|
$toast.error('Sua sessão expirou. Faça login novamente.', { duration: 8000 })
|
||||||
|
await navigateTo('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rankings.value = []
|
||||||
|
errorMessage.value = error?.data?.message ?? 'Erro ao carregar o ranking de jogos. Tente novamente.'
|
||||||
|
$toast.error(errorMessage.value, { duration: 8000 })
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchFavorites() {
|
||||||
|
if (!token.value) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await $fetch(`${WISHLIST_API_BASE_URL}/api/wishlist`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token.value}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const ids = new Set(
|
||||||
|
(data?.data ?? [])
|
||||||
|
.filter((item) => item.is_favorite === 1 || item.is_favorite === true)
|
||||||
|
.map((item) => item.game_id)
|
||||||
|
)
|
||||||
|
favoriteIds.value = ids
|
||||||
|
} catch {
|
||||||
|
// falha silenciosa — favoritos são secundários ao ranking
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function toggleFavorite(game) {
|
||||||
|
if (!token.value) {
|
||||||
|
await navigateTo('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const gameId = game.name
|
||||||
|
togglingId.value = gameId
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (favoriteIds.value.has(gameId)) {
|
||||||
|
await $fetch(`${WISHLIST_API_BASE_URL}/api/wishlist/${encodeURIComponent(gameId)}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token.value}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
favoriteIds.value = new Set([...favoriteIds.value].filter((id) => id !== gameId))
|
||||||
|
$toast.success(`${gameId} removido dos favoritos.`, { duration: 4000 })
|
||||||
|
} else {
|
||||||
|
await $fetch(`${WISHLIST_API_BASE_URL}/api/wishlist`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token.value}`
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
game_id: gameId,
|
||||||
|
is_wishlist: false,
|
||||||
|
is_favorite: true,
|
||||||
|
price_alert: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
favoriteIds.value = new Set([...favoriteIds.value, gameId])
|
||||||
|
$toast.success(`${gameId} adicionado aos favoritos!`, { duration: 4000 })
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const statusCode = error?.statusCode ?? error?.response?.status ?? error?.data?.statusCode
|
||||||
|
|
||||||
|
if (statusCode === 401) {
|
||||||
|
clearToken()
|
||||||
|
$toast.error('Sua sessão expirou. Faça login novamente.', { duration: 8000 })
|
||||||
|
await navigateTo('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$toast.error('Erro ao atualizar favoritos. Tente novamente.', { duration: 6000 })
|
||||||
|
} finally {
|
||||||
|
togglingId.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fetchRankings()
|
||||||
|
fetchFavorites()
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(selectedRanking, () => {
|
||||||
|
if (import.meta.client) {
|
||||||
|
fetchRankings()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -1,5 +1,63 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div
|
||||||
<h1>Welcome to the Home Page</h1>
|
class="relative grid min-h-screen place-items-center overflow-hidden bg-[#f5f5f5] px-4 py-12 font-sans text-[#0c0a09] md:py-24"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="pointer-events-none absolute left-1/2 top-10 h-[420px] w-[min(92vw,760px)] -translate-x-1/2 rounded-[48px] bg-[radial-gradient(circle_at_20%_30%,rgba(167,229,211,0.62),transparent_28%),radial-gradient(circle_at_72%_24%,rgba(244,197,168,0.56),transparent_30%),radial-gradient(circle_at_52%_78%,rgba(200,184,224,0.5),transparent_34%)] blur-2xl"
|
||||||
|
aria-hidden="true"
|
||||||
|
></div>
|
||||||
|
|
||||||
|
<main
|
||||||
|
class="relative grid w-full max-w-[960px] gap-8 rounded-2xl border border-[#e7e5e4] bg-white p-6 shadow-[0_4px_16px_rgba(0,0,0,0.04)] md:grid-cols-[minmax(0,1fr)_auto] md:items-end md:p-8"
|
||||||
|
aria-labelledby="landing-title"
|
||||||
|
>
|
||||||
|
<section>
|
||||||
|
<p
|
||||||
|
class="m-0 inline-flex rounded-full bg-[rgba(167,229,211,0.62)] px-3 py-1 text-xs font-semibold uppercase leading-[1.4] tracking-[0.96px] text-[#0c0a09]"
|
||||||
|
>
|
||||||
|
Autenticação
|
||||||
|
</p>
|
||||||
|
<h1
|
||||||
|
id="landing-title"
|
||||||
|
class="my-5 max-w-[640px] font-serif text-[40px] font-light leading-[1.05] tracking-[-1.2px] text-[#0c0a09] md:text-[64px] md:tracking-[-1.92px]"
|
||||||
|
>
|
||||||
|
Acesse sua conta
|
||||||
|
</h1>
|
||||||
|
<p
|
||||||
|
class="m-0 max-w-[520px] text-base font-normal leading-6 tracking-[0.16px] text-[#4e4e4e]"
|
||||||
|
>
|
||||||
|
Entre para ver sua área autenticada ou crie uma conta nova com email e senha.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<nav class="flex flex-col gap-3 sm:flex-row md:flex-col" aria-label="Acesso a conta">
|
||||||
|
<NuxtLink
|
||||||
|
v-if="hasToken"
|
||||||
|
to="/home"
|
||||||
|
class="inline-flex h-10 items-center justify-center rounded-full bg-[#292524] px-5 text-[15px] font-medium leading-none text-white transition hover:bg-[#0c0a09] active:bg-[#0c0a09]"
|
||||||
|
>
|
||||||
|
Ir para home
|
||||||
|
</NuxtLink>
|
||||||
|
<NuxtLink
|
||||||
|
v-else
|
||||||
|
to="/login"
|
||||||
|
class="inline-flex h-10 items-center justify-center rounded-full bg-[#292524] px-5 text-[15px] font-medium leading-none text-white transition hover:bg-[#0c0a09] active:bg-[#0c0a09]"
|
||||||
|
>
|
||||||
|
Entrar na conta
|
||||||
|
</NuxtLink>
|
||||||
|
<NuxtLink
|
||||||
|
to="/criar-conta"
|
||||||
|
class="inline-flex h-10 items-center justify-center rounded-full border border-[#d6d3d1] bg-transparent px-5 text-[15px] font-medium leading-none text-[#0c0a09] transition hover:border-[#0c0a09]"
|
||||||
|
>
|
||||||
|
Criar conta
|
||||||
|
</NuxtLink>
|
||||||
|
</nav>
|
||||||
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
const token = useCookie('token')
|
||||||
|
|
||||||
|
const hasToken = computed(() => Boolean(token.value))
|
||||||
|
</script>
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
import { PrismaClient } from '@prisma/client'
|
|
||||||
|
|
||||||
const prismaClientSingleton = () => {
|
|
||||||
return new PrismaClient()
|
|
||||||
}
|
|
||||||
|
|
||||||
declare const globalThis: {
|
|
||||||
prismaGlobal: ReturnType<typeof prismaClientSingleton>
|
|
||||||
} & typeof global
|
|
||||||
|
|
||||||
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton()
|
|
||||||
|
|
||||||
export default prisma
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma
|
|
||||||
@@ -2,7 +2,13 @@
|
|||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
compatibilityDate: '2025-07-15',
|
compatibilityDate: '2025-07-15',
|
||||||
devtools: { enabled: true },
|
devtools: { enabled: true },
|
||||||
modules: ['@nuxtjs/tailwindcss', '@pinia/nuxt', '@prisma/nuxt', '@vee-validate/nuxt', 'vue-sonner/nuxt', '@nuxt/icon'],
|
modules: [
|
||||||
|
'@nuxtjs/tailwindcss',
|
||||||
|
'@pinia/nuxt',
|
||||||
|
'@vee-validate/nuxt',
|
||||||
|
'vue-sonner/nuxt',
|
||||||
|
'@nuxt/icon'
|
||||||
|
],
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
databaseUrl: process.env.DATABASE_URL,
|
databaseUrl: process.env.DATABASE_URL,
|
||||||
jwtIssuer: process.env.JWT_ISSUER ?? 'https://auth.local',
|
jwtIssuer: process.env.JWT_ISSUER ?? 'https://auth.local',
|
||||||
@@ -14,18 +20,12 @@ export default defineNuxtConfig({
|
|||||||
jwtKid: process.env.JWT_KID ?? 'auth-key-1',
|
jwtKid: process.env.JWT_KID ?? 'auth-key-1',
|
||||||
refreshTokenPepper: process.env.REFRESH_TOKEN_PEPPER ?? '',
|
refreshTokenPepper: process.env.REFRESH_TOKEN_PEPPER ?? '',
|
||||||
passwordResetTtlSec: process.env.PASSWORD_RESET_TTL_SEC ?? '900',
|
passwordResetTtlSec: process.env.PASSWORD_RESET_TTL_SEC ?? '900',
|
||||||
passwordResetTokenPepper: process.env.PASSWORD_RESET_TOKEN_PEPPER ?? ''
|
passwordResetTokenPepper: process.env.PASSWORD_RESET_TOKEN_PEPPER ?? '',
|
||||||
|
passwordResetBaseUrl: process.env.PASSWORD_RESET_BASE_URL ?? ''
|
||||||
},
|
},
|
||||||
vite: {
|
vite: {
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
include: [
|
include: ['@vue/devtools-core', '@vue/devtools-kit', 'zod', '@vee-validate/zod', 'vue-sonner']
|
||||||
'@vue/devtools-core',
|
|
||||||
'@vue/devtools-kit',
|
|
||||||
'@prisma/nuxt > @prisma/client',
|
|
||||||
'zod',
|
|
||||||
'@vee-validate/zod',
|
|
||||||
'vue-sonner',
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export interface AuthRuntimeConfig {
|
|||||||
kid: string
|
kid: string
|
||||||
refreshTokenPepper: string
|
refreshTokenPepper: string
|
||||||
passwordResetTokenPepper: string
|
passwordResetTokenPepper: string
|
||||||
|
passwordResetBaseUrl: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,6 +86,7 @@ export function getAuthRuntimeConfig(event?: H3Event): AuthRuntimeConfig {
|
|||||||
const refreshTokenPepper = String(runtimeConfig.refreshTokenPepper ?? '').trim()
|
const refreshTokenPepper = String(runtimeConfig.refreshTokenPepper ?? '').trim()
|
||||||
const passwordResetTokenPepper =
|
const passwordResetTokenPepper =
|
||||||
String(runtimeConfig.passwordResetTokenPepper ?? '').trim() || refreshTokenPepper
|
String(runtimeConfig.passwordResetTokenPepper ?? '').trim() || refreshTokenPepper
|
||||||
|
const passwordResetBaseUrl = String(runtimeConfig.passwordResetBaseUrl ?? '').trim()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
issuer,
|
issuer,
|
||||||
@@ -99,6 +101,7 @@ export function getAuthRuntimeConfig(event?: H3Event): AuthRuntimeConfig {
|
|||||||
privateKeyPem: normalizePem(String(runtimeConfig.jwtPrivateKeyPem ?? ''), 'JWT private key'),
|
privateKeyPem: normalizePem(String(runtimeConfig.jwtPrivateKeyPem ?? ''), 'JWT private key'),
|
||||||
publicKeyPem: normalizePem(String(runtimeConfig.jwtPublicKeyPem ?? ''), 'JWT public key'),
|
publicKeyPem: normalizePem(String(runtimeConfig.jwtPublicKeyPem ?? ''), 'JWT public key'),
|
||||||
refreshTokenPepper,
|
refreshTokenPepper,
|
||||||
passwordResetTokenPepper
|
passwordResetTokenPepper,
|
||||||
|
passwordResetBaseUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Prisma } from '@prisma/client'
|
import { Prisma } from '@prisma/client'
|
||||||
import { createError, readBody, setResponseStatus, type H3Event } from 'h3'
|
import { createError, getRequestURL, readBody, setResponseStatus, type H3Event } from 'h3'
|
||||||
|
|
||||||
import { signAccessToken } from './jwt'
|
import { signAccessToken } from './jwt'
|
||||||
import { getAuthRuntimeConfig } from './auth-config'
|
import { getAuthRuntimeConfig } from './auth-config'
|
||||||
@@ -202,6 +202,7 @@ export async function handleForgotPassword(event: H3Event) {
|
|||||||
const expiresAt = new Date(now.getTime() + config.passwordResetTtlSec * 1000)
|
const expiresAt = new Date(now.getTime() + config.passwordResetTtlSec * 1000)
|
||||||
const rawResetToken = generateRawPasswordResetToken()
|
const rawResetToken = generateRawPasswordResetToken()
|
||||||
const tokenHash = hashPasswordResetToken(rawResetToken, config.passwordResetTokenPepper)
|
const tokenHash = hashPasswordResetToken(rawResetToken, config.passwordResetTokenPepper)
|
||||||
|
const resetBaseUrl = config.passwordResetBaseUrl || getRequestURL(event).origin
|
||||||
|
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: { email },
|
where: { email },
|
||||||
@@ -233,7 +234,7 @@ export async function handleForgotPassword(event: H3Event) {
|
|||||||
message: 'If the email exists, recovery instructions were generated',
|
message: 'If the email exists, recovery instructions were generated',
|
||||||
recovery: {
|
recovery: {
|
||||||
reset_token: rawResetToken,
|
reset_token: rawResetToken,
|
||||||
reset_url: buildPasswordResetPreviewUrl(config.issuer, rawResetToken),
|
reset_url: buildPasswordResetPreviewUrl(resetBaseUrl, rawResetToken),
|
||||||
expires_in: config.passwordResetTtlSec
|
expires_in: config.passwordResetTtlSec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ export function generateRawPasswordResetToken(): string {
|
|||||||
/**
|
/**
|
||||||
* Monta uma URL de preview para facilitar testes locais sem SMTP.
|
* Monta uma URL de preview para facilitar testes locais sem SMTP.
|
||||||
*
|
*
|
||||||
* @param issuer Base do serviço de auth.
|
* @param baseUrl URL pública usada para abrir a tela de redefinição.
|
||||||
* @param token Token bruto de recuperação.
|
* @param token Token bruto de recuperação.
|
||||||
* @returns URL completa (ou fallback relativo) com o token.
|
* @returns URL completa (ou fallback relativo) com o token.
|
||||||
*/
|
*/
|
||||||
export function buildPasswordResetPreviewUrl(issuer: string, token: string): string {
|
export function buildPasswordResetPreviewUrl(baseUrl: string, token: string): string {
|
||||||
try {
|
try {
|
||||||
const url = new URL('/auth/reset-password', issuer)
|
const url = new URL('/auth/reset-password', baseUrl)
|
||||||
url.searchParams.set('token', token)
|
url.searchParams.set('token', token)
|
||||||
|
|
||||||
return url.toString()
|
return url.toString()
|
||||||
|
|||||||
Reference in New Issue
Block a user