-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (34 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const express = require('express');
const bodyParser = require('body-parser');
const { createClient } = require('@supabase/supabase-js');
require('dotenv').config();
const app = express();
const port = process.env.PORT || 3000;
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseKey = process.env.SUPABASE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);
app.use(bodyParser.json());
app.use(express.static('public'));
app.post('/api/signup', async (req, res) => {
const { name, email } = req.body;
console.log('Request body:', req.body);
if (!name || !email) {
return res.status(400).json({ error: 'Name and email are required' });
}
try {
const { data, error } = await supabase
.from('users')
.insert([{ name, email }]);
if (error) {
throw error;
}
console.log('Inserted data:', data);
res.status(200).json({ message: 'User signed up successfully', data });
} catch (error) {
console.error('Error:', error.message);
res.status(500).json({ error: error.message });
}
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});