mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 22:29:11 +03:00
* Deprecate use of getWithTimeout, refactor BuildingState and RestoringState to use RQ * Refactor profile-create-mutation to use data/fetchers, and edge-function-status-query to use fetch * Shift post from lib/common/fetch, refactor bucket-object-download-mutation * Address feedback * Minor fix * Refactor post calls from lib/common/fetch in auth pages to data/fetchers * Add missing POST users endpoint + small fix when deleting user via context menu * simplify handleFetchError * allow handleFetchError to accept unknown * non-breaking change --------- Co-authored-by: Alaister Young <a@alaisteryoung.com>
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { NextApiRequest, NextApiResponse } from 'next'
|
|
|
|
import { fetchPost } from 'data/fetchers'
|
|
import { constructHeaders } from 'lib/api/apiHelpers'
|
|
import apiWrapper from 'lib/api/apiWrapper'
|
|
|
|
export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler)
|
|
|
|
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
const { method } = req
|
|
|
|
switch (method) {
|
|
case 'POST':
|
|
return handlePost(req, res)
|
|
default:
|
|
res.setHeader('Allow', ['POST'])
|
|
res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })
|
|
}
|
|
}
|
|
|
|
const handlePost = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
const headers = constructHeaders({
|
|
'Content-Type': 'application/json',
|
|
Accept: 'application/json',
|
|
Authorization: `Bearer ${process.env.SUPABASE_SERVICE_KEY}`,
|
|
})
|
|
const url = `${process.env.SUPABASE_URL}/auth/v1/magiclink`
|
|
const payload = { email: req.body.email }
|
|
|
|
const response = await fetchPost(url, payload, { headers })
|
|
if (response.error) {
|
|
const { code, message } = response.error
|
|
return res.status(code).json({ message })
|
|
} else {
|
|
return res.status(200).json(response)
|
|
}
|
|
}
|