mirror of
https://github.com/fergalmoran/supanextail.git
synced 2025-12-22 09:17:54 +00:00
Continue typescript integration
This commit is contained in:
21
pages/api/getUser.ts
Normal file
21
pages/api/getUser.ts
Normal 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;
|
||||
Reference in New Issue
Block a user