Skip to content

Instantly share code, notes, and snippets.

View iMichaelOwolabi's full-sized avatar
✌️
Impossible is Nothing!

Michael Owolabi iMichaelOwolabi

✌️
Impossible is Nothing!
View GitHub Profile
@iMichaelOwolabi
iMichaelOwolabi / event-mngr-init-authController.js
Created July 4, 2022 06:05
Event manager auth controller code
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
@iMichaelOwolabi
iMichaelOwolabi / pa-user-repo.js
Created September 30, 2022 17:30
User repo sample code for the passwordless auth
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' },
@iMichaelOwolabi
iMichaelOwolabi / pa-authRouter.js
Created September 30, 2022 17:34
Routes file for the passwordless auth app
import { Router } from 'express';
import {
createAccount,
login,
verifyUser,
} from '../controllers/authController.js';
import { authGuard } from '../middleware/index.js';
const authRouter = Router();
@iMichaelOwolabi
iMichaelOwolabi / pa-auth-controller.js
Last active September 30, 2022 23:49
AUth controller functions for the passwordless auth
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
@iMichaelOwolabi
iMichaelOwolabi / pa-auth-email-transporter.js
Created September 30, 2022 20:46
Email transporter code for passwordless auth app
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,
@iMichaelOwolabi
iMichaelOwolabi / pa-final-index.js
Created September 30, 2022 23:34
Final index.js code for the passwordless auth app
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;