mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat: add explicit OpenCode host import and repo relink (#176)
* feat: add explicit OpenCode host import and repo relink * fix: tighten OpenCode import and relink reporting * Add OpenCode config schema and JSONC parser imports * Fix repo relinking and state availability detection for config-only imports * Remove unused exports and internalize row-shape types * Remove unused reserveScheduleJobNextRun function --------- Co-authored-by: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com>
This commit is contained in:
1 parent
173dbf578e
commit
6b1a1e2005
15 files changed
+1031
-245
No files matched your search
@@ -40,62 +40,4 @@ export function createAuthMiddleware(auth: AuthInstance) {
|
||||
})
|
||||
}
|
||||
|
||||
export function createOptionalAuthMiddleware(auth: AuthInstance) {
|
||||
return createMiddleware<{
|
||||
Variables: {
|
||||
session: Session['session'] | null
|
||||
user: Session['user'] | null
|
||||
}
|
||||
}>(async (c, next) => {
|
||||
try {
|
||||
const session = await auth.api.getSession({
|
||||
headers: c.req.raw.headers,
|
||||
})
|
||||
|
||||
if (session) {
|
||||
c.set('session', session.session as Session['session'])
|
||||
c.set('user', session.user as Session['user'])
|
||||
} else {
|
||||
c.set('session', null)
|
||||
c.set('user', null)
|
||||
}
|
||||
} catch {
|
||||
c.set('session', null)
|
||||
c.set('user', null)
|
||||
}
|
||||
|
||||
await next()
|
||||
})
|
||||
}
|
||||
|
||||
export function createAdminMiddleware(auth: AuthInstance) {
|
||||
return createMiddleware<{
|
||||
Variables: {
|
||||
session: Session['session']
|
||||
user: Session['user']
|
||||
}
|
||||
}>(async (c, next) => {
|
||||
let session
|
||||
try {
|
||||
session = await auth.api.getSession({
|
||||
headers: c.req.raw.headers,
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Session lookup failed', { error })
|
||||
return c.json({ error: 'Internal Server Error' }, 500)
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
return c.json({ error: 'Unauthorized' }, 401)
|
||||
}
|
||||
|
||||
const user = session.user as Session['user']
|
||||
if (user.role !== 'admin') {
|
||||
return c.json({ error: 'Forbidden: Admin access required' }, 403)
|
||||
}
|
||||
|
||||
c.set('session', session.session as Session['session'])
|
||||
c.set('user', user)
|
||||
await next()
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user