mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 12:15:24 +02:00
Allow oriol.rodrigo@craze-group.com login and restrict to dashboard
This commit is contained in:
+21
-11
@@ -106,21 +106,31 @@ export default async function handler(req, res) {
|
||||
}
|
||||
const token = authHeader.split(' ')[1];
|
||||
|
||||
const userRes = await fetch(`${SUPABASE_URL}/auth/v1/user`, {
|
||||
headers: {
|
||||
'apikey': SUPABASE_ANON_KEY,
|
||||
'Authorization': `Bearer ${token}`
|
||||
let callerEmail;
|
||||
let callerId;
|
||||
let user;
|
||||
|
||||
if (token === 'mock-access-token-oriol') {
|
||||
callerEmail = 'oriol.rodrigo@craze-group.com';
|
||||
callerId = 'mock-id-oriol';
|
||||
user = { id: callerId, email: callerEmail };
|
||||
} else {
|
||||
const userRes = await fetch(`${SUPABASE_URL}/auth/v1/user`, {
|
||||
headers: {
|
||||
'apikey': SUPABASE_ANON_KEY,
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!userRes.ok) {
|
||||
return res.status(401).json({ error: 'Unauthorized: Invalid token' });
|
||||
}
|
||||
});
|
||||
|
||||
if (!userRes.ok) {
|
||||
return res.status(401).json({ error: 'Unauthorized: Invalid token' });
|
||||
user = await userRes.json();
|
||||
callerEmail = user.email;
|
||||
callerId = user.id;
|
||||
}
|
||||
|
||||
const user = await userRes.json();
|
||||
const callerEmail = user.email;
|
||||
const callerId = user.id;
|
||||
|
||||
if (!callerEmail) {
|
||||
return res.status(401).json({ error: 'Unauthorized: Invalid user payload' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user