-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathroute.ts
More file actions
50 lines (48 loc) · 1.37 KB
/
Copy pathroute.ts
File metadata and controls
50 lines (48 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { ApiError } from '@/lib/errors'
import * as fs from 'fs'
import { NextResponse } from 'next/server'
import * as path from 'path'
/**
* API route to clear the persisted Spotify token file.
* This is called during logout to ensure a fresh authentication flow.
*/
export async function POST(_req: Request) {
try {
const tokenFilePath = path.join(
process.cwd(),
'logs',
'spotify_tokens.json'
)
// Check if file exists before attempting to delete
if (fs.existsSync(tokenFilePath)) {
fs.unlinkSync(tokenFilePath)
console.log('[API /clear-token] Deleted spotify_tokens.json')
return NextResponse.json({
success: true,
message: 'Token file cleared',
})
} else {
console.log('[API /clear-token] Token file does not exist')
return NextResponse.json({
success: true,
message: 'Token file already cleared',
})
}
} catch (error) {
if (error instanceof ApiError) {
return NextResponse.json(
{ error: error.message },
{ status: error.statusCode }
)
}
console.error('[API /clear-token] Error clearing token file:', error)
return NextResponse.json(
{
success: false,
error: 'Failed to clear token file',
details: error instanceof Error ? error.message : String(error),
},
{ status: 500 }
)
}
}