-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d23bd0d
commit d79e819
Showing
16 changed files
with
82 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
auth-service/node_modules/ | ||
auth-service/.env | ||
meetup-service/.env | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
PORT=5000 | ||
DATABASE_URL=postgres://postgres:rootroot@localhost:5432/meetups | ||
JWT_SECRET=your_jwt_secret_key | ||
DATABASE_URL=postgres://postgres:rootroot@localhost:5000/meetups #localhost:5432 | ||
JWT_SECRET=secret_key | ||
SALT_ROUNDS=10 | ||
SESSION_EXPIRY='7d' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"nodemon": "^2.0.15" | ||
}, | ||
"author": "Artem", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"type": "module" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
const { DataTypes } = require('sequelize'); | ||
const sequelize = require('../config/database'); | ||
import { DataTypes } from 'sequelize'; | ||
import sequelize from '../config/database.js'; | ||
|
||
const User = sequelize.define('User', { | ||
id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true }, | ||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, | ||
username: { type: DataTypes.STRING, unique: true, allowNull: false }, | ||
email: { type: DataTypes.STRING, unique: true, allowNull: false }, | ||
password: { type: DataTypes.STRING, allowNull: false }, | ||
createdAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW }, | ||
updatedAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW }, | ||
}, | ||
{ tableName: 'users' } | ||
); | ||
firstName: DataTypes.STRING, | ||
lastName: DataTypes.STRING, | ||
avatarUrl: DataTypes.STRING, | ||
bio: DataTypes.TEXT, | ||
}, { | ||
tableName: 'users', | ||
timestamps: true, | ||
}); | ||
|
||
module.exports = User; | ||
export default User; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
const User = require('../models/userModel'); | ||
import User from '../models/userModel.js'; | ||
|
||
exports.createUser = async (userData) => { | ||
export const createUser = async (userData) => { | ||
return await User.create(userData); | ||
}; | ||
|
||
exports.findUserByEmail = async (email) => { | ||
export const findUserByEmail = async (email) => { | ||
return await User.findOne({ where: { email } }); | ||
}; | ||
|
||
exports.updateUser = async (userId, updatedData) => { | ||
export const updateUser = async (userId, updatedData) => { | ||
await User.update(updatedData, { where: { id: userId } }); | ||
return await User.findByPk(userId); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
const bcrypt = require('bcryptjs'); | ||
const jwt = require('jsonwebtoken'); | ||
const userRepository = require('../repositories/userRepository'); | ||
const { JWT_SECRET } = process.env; | ||
import bcrypt from 'bcryptjs'; | ||
import jwt from 'jsonwebtoken'; | ||
import * as userRepository from '../repositories/userRepository.js'; | ||
|
||
exports.registerUser = async (userData) => { | ||
const hashedPassword = await bcrypt.hash(userData.password, 10); | ||
const { JWT_SECRET, SALT_ROUNDS, SESSION_EXPIRY } = process.env; | ||
|
||
export const registerUser = async (userData) => { | ||
const hashedPassword = await bcrypt.hash(userData.password, parseInt(SALT_ROUNDS)); | ||
const user = await userRepository.createUser({ ...userData, password: hashedPassword }); | ||
return { id: user.id, email: user.email }; | ||
}; | ||
|
||
exports.loginUser = async ({ email, password }) => { | ||
export const loginUser = async ({ email, password }) => { | ||
const user = await userRepository.findUserByEmail(email); | ||
if (!user || !(await bcrypt.compare(password, user.password))) { | ||
throw new Error('Invalid credentials'); | ||
} | ||
return jwt.sign({ id: user.id, email: user.email }, JWT_SECRET, { expiresIn: '1h' }); | ||
return jwt.sign({ id: user.id, email: user.email }, JWT_SECRET, { expiresIn: SESSION_EXPIRY }); | ||
}; | ||
|
||
exports.updateProfile = async (userId, newProfileData) => { | ||
export const updateProfile = async (userId, newProfileData) => { | ||
return await userRepository.updateUser(userId, newProfileData); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters