(event: HandlerEvent<"HTTP">, logger: Logger)
| 801 | } |
| 802 | |
| 803 | async function webhookHandler(event: HandlerEvent<"HTTP">, logger: Logger) { |
| 804 | logger.debug("[inside supabase management integration] Handling webhook handler"); |
| 805 | |
| 806 | const { rawEvent: request, source } = event; |
| 807 | |
| 808 | if (!request.body) { |
| 809 | logger.debug("[inside supabase management integration] No body found"); |
| 810 | |
| 811 | return; |
| 812 | } |
| 813 | |
| 814 | // Check the Bearer token matches the secret |
| 815 | const authHeader = request.headers.get("Authorization"); |
| 816 | |
| 817 | if (!authHeader) { |
| 818 | logger.debug("[inside supabase management integration] No Authorization header found"); |
| 819 | |
| 820 | return { events: [] }; |
| 821 | } |
| 822 | |
| 823 | const authHeaderParts = authHeader.split(" "); |
| 824 | |
| 825 | if (authHeaderParts.length !== 2) { |
| 826 | logger.debug( |
| 827 | "[inside supabase management integration] Authorization header is not in the correct format" |
| 828 | ); |
| 829 | |
| 830 | return { events: [] }; |
| 831 | } |
| 832 | |
| 833 | const token = authHeaderParts[1]; |
| 834 | |
| 835 | if (token !== source.secret) { |
| 836 | logger.debug( |
| 837 | "[inside supabase management integration] Authorization header does not match the secret" |
| 838 | ); |
| 839 | |
| 840 | return { events: [] }; |
| 841 | } |
| 842 | |
| 843 | const rawBody = await request.text(); |
| 844 | |
| 845 | const payload = safeParseBody(rawBody); |
| 846 | |
| 847 | if (!payload) { |
| 848 | return { events: [] }; |
| 849 | } |
| 850 | |
| 851 | // Generate a unique ID for the event |
| 852 | const id = randomUUID(); |
| 853 | |
| 854 | return { |
| 855 | events: [ |
| 856 | { |
| 857 | id, |
| 858 | name: payload.type, |
| 859 | source: "supabase", |
| 860 | payload, |
nothing calls this directly
no test coverage detected
searching dependent graphs…