mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
Feature ## What is the current behavior? Incident banner logic depends on StatusPage and Supabase project for metadata. ## What is the new behavior? New incident banner logic that depends only on incident.io. Displays in non-production environments for now because I haven't wired up the rest of the workflow. This is just to allow a total end-to-end testing/playground for test incidents <-> Slack <-> preview dashboard for people to try out the UX. ## Additional context You can test using my [test incident](https://app.incident.io/supabase/incidents/405). This has severity minor, so the preview site should have a banner. Toggle to informative, hard refresh dashboard with cache off, and banner should disappear. Toggle back to minor, hard refresh without cache again, and banner should reappear. Same thing if you edit the "Banner shown" field from 1 to -1 and back.
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import type { JwtPayload } from '@supabase/supabase-js'
|
|
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
import { ResponseError, ResponseFailure } from 'types'
|
|
|
|
import { IS_PLATFORM } from '../constants'
|
|
import { apiAuthenticate } from './apiAuthenticate'
|
|
|
|
export function isResponseOk<T>(response: T | ResponseFailure | undefined): response is T {
|
|
if (response === undefined || response === null) {
|
|
return false
|
|
}
|
|
|
|
if (response instanceof ResponseError) {
|
|
return false
|
|
}
|
|
|
|
if (typeof response === 'object' && 'error' in response && Boolean(response.error)) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// Purpose of this apiWrapper is to function like a global catchall for ANY errors
|
|
// It's a safety net as the API service should never drop, nor fail
|
|
|
|
export default async function apiWrapper(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse,
|
|
handler: (
|
|
req: NextApiRequest,
|
|
res: NextApiResponse,
|
|
claims?: JwtPayload
|
|
) => Promise<NextApiResponse | Response | void>,
|
|
options?: { withAuth: boolean }
|
|
): Promise<NextApiResponse | Response | void> {
|
|
try {
|
|
const { withAuth } = options || {}
|
|
let claims: JwtPayload | undefined
|
|
|
|
if (IS_PLATFORM && withAuth) {
|
|
const response = await apiAuthenticate(req, res)
|
|
if (!isResponseOk(response)) {
|
|
return res.status(401).json({
|
|
error: {
|
|
message: `Unauthorized: ${response.error.message}`,
|
|
},
|
|
})
|
|
}
|
|
claims = response
|
|
}
|
|
|
|
return handler(req, res, claims)
|
|
} catch (error) {
|
|
return res.status(500).json({ error })
|
|
}
|
|
}
|