Skip to content

Commit caeff85

Browse files
committed
fix(api): use Fastify/Pino logger instead of console for auth logs
1 parent 1adf493 commit caeff85

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

api/server.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env npx ts-node
22
/**
33
* BluePLM REST API Server (Fastify + TypeScript)
4-
* Build: 2025-12-14T06:25-v2.1.2
4+
* Build: 2025-12-14T06:26-v2.1.3-pino
55
*
66
* Integration API for external systems (ERP, CI/CD, Slack, etc.)
77
*
@@ -709,7 +709,7 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
709709
const authHeader = request.headers.authorization
710710

711711
if (!authHeader || !authHeader.startsWith('Bearer ')) {
712-
console.warn('[Auth] Missing or invalid auth header')
712+
request.log.warn('[Auth] Missing or invalid auth header')
713713
return reply.code(401).send({
714714
error: 'Unauthorized',
715715
message: 'Missing or invalid Authorization header'
@@ -720,7 +720,7 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
720720

721721
// Check for literal "undefined" string (frontend bug protection)
722722
if (!token || token === 'undefined' || token === 'null') {
723-
console.warn('[Auth] Empty or invalid token string')
723+
request.log.warn('[Auth] Empty or invalid token string')
724724
return reply.code(401).send({
725725
error: 'Unauthorized',
726726
message: 'Invalid or missing access token'
@@ -733,7 +733,8 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
733733

734734
if (error || !user) {
735735
// Log detailed auth failure for debugging
736-
console.error('[Auth] Token verification failed:', {
736+
request.log.error({
737+
msg: '[Auth] Token verification failed',
737738
error: error?.message,
738739
errorCode: error?.code,
739740
hasUser: !!user,
@@ -753,15 +754,15 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
753754
.single()
754755

755756
if (profileError || !profile) {
756-
console.error('[Auth] Profile lookup failed:', profileError?.message)
757+
request.log.error({ msg: '[Auth] Profile lookup failed', error: profileError?.message })
757758
return reply.code(401).send({
758759
error: 'Profile not found',
759760
message: 'User profile does not exist'
760761
})
761762
}
762763

763764
if (!profile.org_id) {
764-
console.warn('[Auth] User has no organization:', profile.email)
765+
request.log.warn({ msg: '[Auth] User has no organization', email: profile.email })
765766
return reply.code(403).send({
766767
error: 'No organization',
767768
message: 'User is not a member of any organization'
@@ -772,9 +773,9 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
772773
request.user = profile as UserProfile
773774
request.supabase = supabase
774775
request.accessToken = token
775-
console.log('[Auth] Authenticated:', profile.email)
776+
request.log.info({ msg: '[Auth] Authenticated', email: profile.email })
776777
} catch (err) {
777-
console.error('[Auth] Unexpected error:', err)
778+
request.log.error({ msg: '[Auth] Unexpected error', error: err })
778779
return reply.code(500).send({
779780
error: 'Auth error',
780781
message: err instanceof Error ? err.message : 'Unknown error'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blue-plm",
3-
"version": "2.1.2",
3+
"version": "2.1.3",
44
"description": "Product Lifecycle Management for engineering teams",
55
"main": "dist-electron/main.js",
66
"scripts": {

0 commit comments

Comments
 (0)