Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions app/api/build-app/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ async function pushFileToGitHub(
)

if (!res.ok) {
const err = (await res.json()) as { message?: string }
console.warn(`[build-app] Failed to push ${path}: ${err.message}`)
const err = (await res.json().catch(() => ({}))) as { message?: string }
throw new Error(`Failed to push ${path}: ${err.message ?? res.statusText}`)
}
}

Expand Down Expand Up @@ -195,8 +195,8 @@ async function pushFileToGitLab(
)

if (!res.ok) {
const err = (await res.json()) as { message?: string }
console.warn(`[build-app] Failed to push ${path} to GitLab: ${err.message}`)
const err = (await res.json().catch(() => ({}))) as { message?: string }
throw new Error(`Failed to push ${path} to GitLab: ${err.message ?? res.statusText}`)
}
}

Expand Down Expand Up @@ -296,19 +296,31 @@ export async function POST(request: NextRequest) {

// Step 3 — push files
let pushed = 0
for (const [path, content] of fileEntries) {
if (platform === 'github') {
await pushFileToGitHub(accessToken, user.github_username, cleanRepoName, path, content)
} else if (gitlabProjectId !== null) {
await pushFileToGitLab(accessToken, gitlabProjectId, gitlabBranch, path, content)
try {
for (const [path, content] of fileEntries) {
if (platform === 'github') {
await pushFileToGitHub(accessToken, user.github_username, cleanRepoName, path, content)
} else if (gitlabProjectId !== null) {
await pushFileToGitLab(accessToken, gitlabProjectId, gitlabBranch, path, content)
}
pushed++
send({
step: 'pushing',
message: `Pushing files… (${pushed}/${fileEntries.length})`,
current: pushed,
total: fileEntries.length,
repoUrl,
})
}
pushed++
} catch (e) {
send({
step: 'pushing',
message: `Pushing files… (${pushed}/${fileEntries.length})`,
current: pushed,
total: fileEntries.length,
step: 'error',
message: e instanceof Error ? e.message : 'Failed to push generated files.',
repoUrl,
filesCreated: pushed,
})
controller.close()
return
}

send({
Expand Down
2 changes: 1 addition & 1 deletion lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async function getCurrentUserFromCookies(): Promise<AuthUser | null> {
LIMIT 1
`
const row = users[0] as AuthUser | undefined
if (row?.access_token === tokenCookie) {
if (row?.access_token && tokenCookie === row.access_token) {
return row
}
if (row && tokenCookie) {
Expand Down