moved randomString to lib

feature/saml-login
Deepak Prabhakara 2021-12-25 22:13:13 +00:00
parent 6c3a79fb54
commit 5ae3083b43
4 changed files with 11 additions and 21 deletions

9
lib/random.ts Normal file
View File

@ -0,0 +1,9 @@
export const randomString = function (length = 12) {
let result = "";
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
};

View File

@ -5,21 +5,12 @@ import { authenticator } from "otplib";
import { ErrorCode, isGoogleLoginEnabled, Session, verifyPassword } from "@lib/auth";
import { symmetricDecrypt } from "@lib/crypto";
import prisma from "@lib/prisma";
import { randomString } from "@lib/random";
import { isSAMLLoginEnabled, samlLoginUrl } from "@lib/saml";
import slugify from "@lib/slugify";
import { IdentityProvider } from ".prisma/client";
function randomString(length = 12) {
let result = "";
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
async function authorize(credentials: any) {
const user = await prisma.user.findUnique({
where: {

View File

@ -1,6 +1,6 @@
import { expect, test } from "@playwright/test";
import { randomString } from "./lib/testUtils";
import { randomString } from "@lib/random";
test.beforeEach(async ({ page }) => {
await page.goto("/event-types");

View File

@ -6,16 +6,6 @@ export function todo(title: string) {
test.skip(title, () => {});
}
export function randomString(length = 12) {
let result = "";
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
type Request = IncomingMessage & { body?: unknown };
type RequestHandlerOptions = { req: Request; res: ServerResponse };
type RequestHandler = (opts: RequestHandlerOptions) => void;