Initial commit, (copy project from auth)
This commit is contained in:
commit
4f0998933b
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Ignore node_modules directory
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Ignore logs
|
||||||
|
logs/
|
||||||
|
|
||||||
|
# Ignore environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# Ignore built files
|
||||||
|
dist/
|
||||||
|
|
||||||
|
# Ignore any editor-specific files
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Ignore any local development configuration files
|
||||||
|
config/local.js
|
||||||
|
|
||||||
|
# Ignore any sensitive or private files
|
||||||
|
secrets/
|
||||||
|
|
||||||
|
# Ignore any temporary files
|
||||||
|
*.tmp
|
||||||
14
README.md
Normal file
14
README.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Auth Service
|
||||||
|
|
||||||
|
Welcome to the Auth Service! This service handles user authentication for the SWave application.
|
||||||
|
|
||||||
|
This microservice is a wrapper for supabase authentication and will return the user and session info returned by them.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
To get started with the Auth Service, follow these steps:
|
||||||
|
|
||||||
|
1. Clone the repository
|
||||||
|
2. Install dependencies: `npm install`
|
||||||
|
3. Set up your .env file with SUPABASE_URL, SUPABASE_KEY and APP_PORT
|
||||||
|
4. Start the server: `node src/index.js`
|
||||||
1202
package-lock.json
generated
Normal file
1202
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
19
package.json
Normal file
19
package.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "swave-auth",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Authentication API microservice for SWave",
|
||||||
|
"main": "index.js",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "DarkBird",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@supabase/supabase-js": "^2.45.4",
|
||||||
|
"body-parser": "^1.20.3",
|
||||||
|
"dotenv": "^16.4.5",
|
||||||
|
"express": "^4.21.0",
|
||||||
|
"nodemon": "^3.1.7"
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/index.js
Normal file
29
src/index.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import express from 'express';
|
||||||
|
import bodyParser from 'body-parser';
|
||||||
|
|
||||||
|
import { setUpRoutes } from './routes.js';
|
||||||
|
import { requestLogger } from './middleware/logger.js';
|
||||||
|
import { supabaseMiddleware } from './middleware/supabase.js';
|
||||||
|
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
function setUpMiddlewares(app) {
|
||||||
|
const jsonParser = bodyParser.json();
|
||||||
|
app.use(jsonParser);
|
||||||
|
app.use(requestLogger);
|
||||||
|
app.use(supabaseMiddleware);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initApplication() {
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
setUpMiddlewares(app);
|
||||||
|
setUpRoutes(app);
|
||||||
|
|
||||||
|
app.listen(process.env.APP_PORT, () => {
|
||||||
|
console.log('Server is running on port 3000');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
initApplication();
|
||||||
8
src/middleware/logger.js
Normal file
8
src/middleware/logger.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export function requestLogger(req, res, next) {
|
||||||
|
console.log('Request received!');
|
||||||
|
console.log('URL:', req.originalUrl);
|
||||||
|
console.log('Method:', req.method);
|
||||||
|
console.log(`Headers:\n${JSON.stringify(req.headers, null, 2)}`);
|
||||||
|
console.log(`Body:\n${JSON.stringify(req.body, null, 2)}`);
|
||||||
|
next();
|
||||||
|
};
|
||||||
6
src/middleware/supabase.js
Normal file
6
src/middleware/supabase.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { createClient } from '@supabase/supabase-js';
|
||||||
|
|
||||||
|
export function supabaseMiddleware(req, res, next) {
|
||||||
|
req.supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY);
|
||||||
|
next();
|
||||||
|
}
|
||||||
37
src/routes.js
Normal file
37
src/routes.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
const register = async (req, res) => {
|
||||||
|
const { email, password } = req.body;
|
||||||
|
const { data, error } = await req.supabase.auth.signUp({
|
||||||
|
email: email,
|
||||||
|
password: password,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return res.status(400).json({ error: error.message });
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(201).json({ user: data.user, session: data.session });
|
||||||
|
}
|
||||||
|
|
||||||
|
const login = async (req, res) => {
|
||||||
|
const { email, password } = req.body;
|
||||||
|
const { data, error } = await req.supabase.auth.signInWithPassword({
|
||||||
|
email: email,
|
||||||
|
password: password,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return res.status(400).json({ error: error.message });
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).json({ user: data.user, session: data.session });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setUpRoutes(app) {
|
||||||
|
app.post('/register', register);
|
||||||
|
app.post('/login', login);
|
||||||
|
|
||||||
|
app.get('/', (req, res) => {
|
||||||
|
res.send('Hello World!');
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user