first commit

This commit is contained in:
Inshal
2024-05-29 22:34:28 +05:00
commit e63fc41a20
1470 changed files with 174828 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
export const db = {
// TODO: Use jsonwebtoken pkg
// Created from https://jwt.io/ using HS256 algorithm
// We didn't created it programmatically because jsonwebtoken package have issues with esm support. View Issues: https://github.com/auth0/node-jsonwebtoken/issues/655
userTokens: [
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MX0.fhc3wykrAnRpcKApKhXiahxaOe8PSHatad31NuIZ0Zg',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Mn0.cat2xMrZLn0FwicdGtZNzL7ifDTAKWB0k1RurSWjdnw',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6M30.PGOfMaZA_T9W05vMj5FYXG5d47soSPJD1WuxeUfw4L4',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NH0.d_9aq2tpeA9-qpqO0X4AmW6gU2UpWkXwc04UJYFWiZE',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NX0.ocO77FbjOSU1-JQ_BilEZq2G_M8bCiB10KYqtfkv1ss',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Nn0.YgQILRqZy8oefhTZgJJfiEzLmhxQT_Bd2510OvrrwB8',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6N30.KH9RmOWIYv_HONxajg7xBIJXHEUvSdcBygFtS2if8Jk',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6OH0.shrp-oMHkVAkiMkv_aIvSx3k6Jk-X7TrH5UeufChz_g',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6OX0.9JD1MR3ZkwHzhl4mOHH6lGG8hOVNZqDNH6UkFzjCqSE',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTB9.txWLuN4QT5PqTtgHmlOiNerIu5Do51PpYOiZutkyXYg',
],
users: [
{
id: 1,
fullName: 'John Doe',
username: 'johndoe',
password: 'admin',
avatar: `${import.meta.env.BASE_URL.replace(/build\/$/g, '') ?? '/'}images/avatars/avatar-1.png`,
email: 'admin@demo.com',
role: 'admin',
abilityRules: [
{
action: 'manage',
subject: 'all',
},
],
},
{
id: 2,
fullName: 'Jane Doe',
username: 'janedoe',
password: 'client',
avatar: `${import.meta.env.BASE_URL.replace(/build\/$/g, '') ?? '/'}images/avatars/avatar-2.png`,
email: 'client@demo.com',
role: 'client',
abilityRules: [
{
action: 'read',
subject: 'AclDemo',
},
],
},
],
}

View File

@@ -0,0 +1,39 @@
import { rest } from 'msw'
import { db } from '@db/auth/db'
export const handlerAuth = [
rest.post(('/api/auth/login'), async (req, res, ctx) => {
const { email, password } = await req.json()
let errors = {
email: ['Something went wrong'],
}
const user = db.users.find(u => u.email === email && u.password === password)
if (user) {
try {
const accessToken = db.userTokens[user.id]
// We are duplicating user here
const userData = { ...user }
const userOutData = Object.fromEntries(Object.entries(userData)
.filter(([key, _]) => !(key === 'password' || key === 'abilityRules')))
const response = {
userAbilityRules: userData.abilityRules,
accessToken,
userData: userOutData,
}
return res(ctx.status(200), ctx.json(response))
}
catch (e) {
errors = { email: [e] }
}
}
else {
errors = { email: ['Invalid email or password'] }
}
return res(ctx.status(400), ctx.json({ errors }))
}),
]

View File

@@ -0,0 +1 @@
export {}