Continue typescript integration

This commit is contained in:
Michael
2021-08-24 11:57:13 +02:00
parent 5a24246d09
commit a7c614bcc9
22 changed files with 278 additions and 85 deletions

21
pages/api/getUser.ts Normal file
View File

@@ -0,0 +1,21 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { supabase } from 'utils/supabaseClient';
// Example of how to verify and get user data server-side.
const getUser = async (req: NextApiRequest, res: NextApiResponse): Promise<void> => {
const token = req.headers.token;
if (typeof token !== 'string') {
return res.status(401).json({ error: 'Missing auth token.' });
}
if (token) {
const { data: user, error } = await supabase.auth.api.getUser(token);
if (error) return res.status(401).json({ error: error.message });
return res.status(200).json(user);
}
};
export default getUser;