mirror of
https://github.com/KeyZox71/knl_meowscendence.git
synced 2025-12-31 21:56:41 +01:00
Merge remote-tracking branch 'origin/main' into user-management
This commit is contained in:
@ -12,6 +12,8 @@ GRAPH_PORT=3000
|
|||||||
ELK_PORT=5601
|
ELK_PORT=5601
|
||||||
|
|
||||||
GOOGLE_CALLBACK_URL=https://localhost:8443/api/v1
|
GOOGLE_CALLBACK_URL=https://localhost:8443/api/v1
|
||||||
|
# the url to which the user will be redirected when it logs with google
|
||||||
|
CALLBACK_REDIR=http://localhost:3000
|
||||||
GOOGLE_CLIENT_SECRET=susAF
|
GOOGLE_CLIENT_SECRET=susAF
|
||||||
GOOGLE_CLIENT_ID=Really
|
GOOGLE_CLIENT_ID=Really
|
||||||
|
|
||||||
@ -24,3 +26,6 @@ SMTP_FROM=<the address to send from>
|
|||||||
SMTP_AUTH_USERNAME=<smtp-user>
|
SMTP_AUTH_USERNAME=<smtp-user>
|
||||||
SMTP_AUTH_PASSWORD=<smtp pass>
|
SMTP_AUTH_PASSWORD=<smtp pass>
|
||||||
EMAIL_TO=<mail to send to>
|
EMAIL_TO=<mail to send to>
|
||||||
|
|
||||||
|
USER_URL=<the url to the user api>
|
||||||
|
AUTH_URL=<the url to the auth api>
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export async function gLogCallback(request, reply, fastify) {
|
|||||||
return reply.code(400).send({ error: "User does not exist" });
|
return reply.code(400).send({ error: "User does not exist" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = fastify.jwt.sign(user);
|
const token = fastify.jwt.sign({ user: user.username});
|
||||||
|
|
||||||
return reply
|
return reply
|
||||||
.setCookie('token', token, {
|
.setCookie('token', token, {
|
||||||
@ -45,9 +45,7 @@ export async function gLogCallback(request, reply, fastify) {
|
|||||||
path: '/',
|
path: '/',
|
||||||
secure: env !== 'development',
|
secure: env !== 'development',
|
||||||
sameSite: 'lax',
|
sameSite: 'lax',
|
||||||
})
|
}).redirect(process.env.CALLBACK_REDIR);
|
||||||
.code(200)
|
|
||||||
.send({ msg: "Login successful" });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
fastify.log.error(error);
|
fastify.log.error(error);
|
||||||
reply.code(500).send({ error: 'Internal server error' });
|
reply.code(500).send({ error: 'Internal server error' });
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
import authDB from '../../utils/authDB.js';
|
import authDB from '../../utils/authDB.js';
|
||||||
|
import { authUserCreate } from '../../utils/authUserCreate.js';
|
||||||
|
|
||||||
var env = process.env.NODE_ENV || 'development';
|
var env = process.env.NODE_ENV || 'development';
|
||||||
|
|
||||||
@ -46,7 +47,9 @@ export async function gRegisterCallback(request, reply, fastify) {
|
|||||||
|
|
||||||
authDB.addUser(user.username, '');
|
authDB.addUser(user.username, '');
|
||||||
|
|
||||||
const token = fastify.jwt.sign(user);
|
authUserCreate(user.username, fastify)
|
||||||
|
|
||||||
|
const token = fastify.jwt.sign({ user: user.username});
|
||||||
|
|
||||||
return reply
|
return reply
|
||||||
.setCookie('token', token, {
|
.setCookie('token', token, {
|
||||||
@ -54,9 +57,7 @@ export async function gRegisterCallback(request, reply, fastify) {
|
|||||||
path: '/',
|
path: '/',
|
||||||
secure: env !== 'development',
|
secure: env !== 'development',
|
||||||
sameSite: 'lax',
|
sameSite: 'lax',
|
||||||
})
|
}).redirect(process.env.CALLBACK_REDIR);
|
||||||
.code(200)
|
|
||||||
.send({ msg: "Register successful" });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
fastify.log.error(error);
|
fastify.log.error(error);
|
||||||
reply.code(500).send({ error: 'Internal server error' });
|
reply.code(500).send({ error: 'Internal server error' });
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import bcrypt from 'bcrypt';
|
|||||||
|
|
||||||
import { isValidString } from '../../utils/authUtils.js';
|
import { isValidString } from '../../utils/authUtils.js';
|
||||||
import authDB from '../../utils/authDB.js';
|
import authDB from '../../utils/authDB.js';
|
||||||
|
import { authUserCreate } from '../../utils/authUserCreate.js';
|
||||||
|
|
||||||
var env = process.env.NODE_ENV || 'development';
|
var env = process.env.NODE_ENV || 'development';
|
||||||
|
|
||||||
@ -36,6 +37,8 @@ export async function register(request, reply, saltRounds, fastify) {
|
|||||||
const hash = await bcrypt.hash(password, saltRounds);
|
const hash = await bcrypt.hash(password, saltRounds);
|
||||||
authDB.addUser(user, hash);
|
authDB.addUser(user, hash);
|
||||||
|
|
||||||
|
authUserCreate(user, fastify)
|
||||||
|
|
||||||
const token = fastify.jwt.sign({ user });
|
const token = fastify.jwt.sign({ user });
|
||||||
|
|
||||||
return reply
|
return reply
|
||||||
|
|||||||
24
src/utils/authUserCreate.js
Normal file
24
src/utils/authUserCreate.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} username
|
||||||
|
* @param {import('fastify').FastifyInstance} fastify
|
||||||
|
*/
|
||||||
|
export async function authUserCreate(username, fastify) {
|
||||||
|
const payload = {
|
||||||
|
displayName: username,
|
||||||
|
};
|
||||||
|
const cookie = fastify.jwt.sign({ user: "admin" });
|
||||||
|
|
||||||
|
const url = process.env.USER_URL || "http://localhost:3002/"
|
||||||
|
|
||||||
|
await axios.post(
|
||||||
|
url + "users/" + username,
|
||||||
|
payload,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Cookie': 'token=' + cookie,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user