This commit is contained in:
Your Name
2026-07-13 09:23:24 +00:00
parent 51e3f3776a
commit 5c8a0c8abb
11 changed files with 405 additions and 115 deletions
+13 -4
View File
@@ -1,6 +1,6 @@
import type { FastifyInstance } from 'fastify'
import type { TrueApiEnv } from '../config.js'
import { getAuthKey, signIn, clearToken, getAuthStatus } from '../services/auth-service.js'
import { getAuthKey, signIn, clearToken, getAuthStatus, setTokenDirect } from '../services/auth-service.js'
import { AppError, extractDebugInfo } from '../services/cises-service.js'
const VALID_ENVS = ['sandbox', 'prod']
@@ -18,6 +18,7 @@ const signInSchema = {
properties: {
uuid: { type: 'string' },
data: { type: 'string' },
inn: { type: 'string' },
},
},
}
@@ -43,11 +44,12 @@ export async function authRoutes(app: FastifyInstance): Promise<void> {
}
})
app.post<{ Body: { uuid: string; data: string } }>('/auth/simpleSignIn', { schema: signInSchema }, async (request, reply) => {
app.post<{ Body: { uuid: string; data: string; inn?: string } }>('/auth/simpleSignIn', { schema: signInSchema }, async (request, reply) => {
const env = parseEnv(request.query as Record<string, string>)
try {
const { uuid, data } = request.body
const result = await signIn(env, { uuid, data })
const { uuid, data, inn } = request.body
const result = await signIn(env, { uuid, data, inn })
request.log.info({ env, token: result.token }, 'auth: token received')
return result
} catch (err) {
if (err instanceof AppError) {
@@ -74,4 +76,11 @@ export async function authRoutes(app: FastifyInstance): Promise<void> {
clearToken(env)
return { success: true }
})
app.post<{ Body: { token: string } }>('/auth/setToken', async (request) => {
const env = parseEnv(request.query as Record<string, string>)
setTokenDirect(env, request.body.token)
request.log.info({ env, tokenPrefix: request.body.token.slice(0, 20) + '...' }, 'auth: token set manually')
return { success: true }
})
}