chore: fix lint issues, remove unused hasAvatar
This commit is contained in:
@@ -105,10 +105,7 @@ export async function registerOAuthSocialRoutes(fastify) {
|
||||
if (!clientId || !clientSecret) return reply.code(503).send({ error: 'VK OAuth не настроен' })
|
||||
|
||||
const redirectUri = `${serverPublic}/api/auth/oauth/vk/callback`
|
||||
const state = fastify.jwt.sign(
|
||||
{ oauth: 'vk', action: 'link', userId: request.user.sub },
|
||||
{ expiresIn: '15m' },
|
||||
)
|
||||
const state = fastify.jwt.sign({ oauth: 'vk', action: 'link', userId: request.user.sub }, { expiresIn: '15m' })
|
||||
|
||||
const url = new URL('https://oauth.vk.com/authorize')
|
||||
url.searchParams.set('client_id', clientId)
|
||||
@@ -128,13 +125,15 @@ export async function registerOAuthSocialRoutes(fastify) {
|
||||
return oauthErrorRedirect(reply, String(query.error_description || query.error || 'ошибка VK'))
|
||||
}
|
||||
|
||||
let statePayload = null
|
||||
try {
|
||||
const raw = typeof query.state === 'string' ? query.state : ''
|
||||
statePayload = fastify.jwt.verify(raw || '')
|
||||
} catch {
|
||||
return oauthErrorRedirect(reply, 'Недействительный state OAuth')
|
||||
}
|
||||
const statePayload = (() => {
|
||||
try {
|
||||
const raw = typeof query.state === 'string' ? query.state : ''
|
||||
return fastify.jwt.verify(raw || '')
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
})()
|
||||
if (!statePayload) return oauthErrorRedirect(reply, 'Недействительный state OAuth')
|
||||
|
||||
const code = typeof query.code === 'string' ? query.code.trim() : ''
|
||||
if (!code) return oauthErrorRedirect(reply, 'Не получен код от VK')
|
||||
@@ -212,10 +211,7 @@ export async function registerOAuthSocialRoutes(fastify) {
|
||||
if (!clientId) return reply.code(503).send({ error: 'Yandex OAuth не настроен' })
|
||||
|
||||
const redirectUri = `${serverPublic}/api/auth/oauth/yandex/callback`
|
||||
const state = fastify.jwt.sign(
|
||||
{ oauth: 'yandex', action: 'link', userId: request.user.sub },
|
||||
{ expiresIn: '15m' },
|
||||
)
|
||||
const state = fastify.jwt.sign({ oauth: 'yandex', action: 'link', userId: request.user.sub }, { expiresIn: '15m' })
|
||||
|
||||
const url = new URL('https://oauth.yandex.ru/authorize')
|
||||
url.searchParams.set('response_type', 'code')
|
||||
@@ -231,13 +227,15 @@ export async function registerOAuthSocialRoutes(fastify) {
|
||||
const query = request.query ?? {}
|
||||
if (query.error) return oauthErrorRedirect(reply, String(query.error))
|
||||
|
||||
let statePayload = null
|
||||
try {
|
||||
const raw = typeof query.state === 'string' ? query.state : ''
|
||||
statePayload = fastify.jwt.verify(raw || '')
|
||||
} catch {
|
||||
return oauthErrorRedirect(reply, 'Недействительный state OAuth')
|
||||
}
|
||||
const statePayload = (() => {
|
||||
try {
|
||||
const raw = typeof query.state === 'string' ? query.state : ''
|
||||
return fastify.jwt.verify(raw || '')
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
})()
|
||||
if (!statePayload) return oauthErrorRedirect(reply, 'Недействительный state OAuth')
|
||||
|
||||
const code = typeof query.code === 'string' ? query.code.trim() : ''
|
||||
if (!code) return oauthErrorRedirect(reply, 'Не получен код от Яндекс')
|
||||
@@ -276,10 +274,7 @@ export async function registerOAuthSocialRoutes(fastify) {
|
||||
const yaUserId = String(info?.id || '')
|
||||
if (!yaUserId) return oauthErrorRedirect(reply, 'Не удалось получить профиль Yandex')
|
||||
|
||||
const emailGuess =
|
||||
(Array.isArray(info?.emails) && info.emails[0]) ||
|
||||
info?.default_email ||
|
||||
null
|
||||
const emailGuess = (Array.isArray(info?.emails) && info.emails[0]) || info?.default_email || null
|
||||
|
||||
if (!emailGuess) return oauthErrorRedirect(reply, 'no_email')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user