This file contains hidden or 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
import { ulid } from 'ulid'; | |
import { hash, compare } from 'bcrypt'; | |
import { redisClient } from '../db/index.js'; | |
import { generateToken } from '../utils/jwtHelper.js'; | |
const createAccount = async (req, res) => { | |
try { | |
const { firstName, lastName, email, password, displayName } = req.body; | |
const userId = ulid(); // Generate id for the user which will be used as the key in Redis |
This file contains hidden or 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
import { Entity, Schema } from 'redis-om'; | |
import { redisClient } from '../db/index.js'; | |
class UserRepository extends Entity {} | |
const userSchema = new Schema(UserRepository, { | |
firstName: { type: 'string' }, | |
lastName: { type: 'string' }, | |
email: { type: 'string' }, | |
userName: { type: 'string' }, |
This file contains hidden or 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
import { Router } from 'express'; | |
import { | |
createAccount, | |
login, | |
verifyUser, | |
} from '../controllers/authController.js'; | |
import { authGuard } from '../middleware/index.js'; | |
const authRouter = Router(); |
This file contains hidden or 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
import { generateToken } from '../utils/jwtHelper.js'; | |
import { userRepository } from '../repository/user.js'; | |
import { emailSender } from '../utils/emailTransporter.js'; | |
const createAccount = async (req, res) => { | |
try { | |
const { firstName, lastName, email, userName } = req.body; | |
// Fetch user information from Redis | |
const existingUser = await userRepository |
This file contains hidden or 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
import nodemailer from 'nodemailer'; | |
import { config } from 'dotenv'; | |
config() | |
export const emailSender = async (to, firstName, token) => { | |
const trasporter = await nodemailer.createTransport({ | |
host: process.env.MAILGUN_SMTP_HOSTNAME, | |
port: process.env.SMTP_PORT, | |
secure: false, |
This file contains hidden or 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
import express from 'express'; | |
import { config } from 'dotenv'; | |
import { authRouter } from './src/routes/authRouter.js'; | |
config(); | |
const app = express(); | |
app.use(express.json()); | |
const port = process.env.PORT ?? 3000; |
OlderNewer