」 feat: now creating user on the user api when registering

This commit is contained in:
2025-10-13 15:10:54 +02:00
parent 967b9d8b88
commit d15161dba4
4 changed files with 33 additions and 0 deletions

View File

@ -24,3 +24,6 @@ SMTP_FROM=<the address to send from>
SMTP_AUTH_USERNAME=<smtp-user>
SMTP_AUTH_PASSWORD=<smtp pass>
EMAIL_TO=<mail to send to>
USER_URL=<the url to the user api>
AUTH_URL=<the url to the auth api>

View File

@ -1,6 +1,7 @@
import axios from 'axios'
import authDB from '../../utils/authDB.js';
import { authUserCreate } from '../../utils/authUserCreate.js';
var env = process.env.NODE_ENV || 'development';
@ -46,6 +47,8 @@ export async function gRegisterCallback(request, reply, fastify) {
authDB.addUser(user.username, '');
authUserCreate(user.username, fastify)
const token = fastify.jwt.sign(user);
return reply

View File

@ -2,6 +2,7 @@ import bcrypt from 'bcrypt';
import { isValidString } from '../../utils/authUtils.js';
import authDB from '../../utils/authDB.js';
import { authUserCreate } from '../../utils/authUserCreate.js';
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);
authDB.addUser(user, hash);
authUserCreate(user, fastify)
const token = fastify.jwt.sign({ user });
return reply

View 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(
"http://localhost:3002/users/" + username,
payload,
{
headers: {
'Cookie': 'token=' + cookie,
},
}
);
}