Skip to content

Commit

Permalink
Merge pull request #7 from tuta-amb/fix/6-email-specialchar
Browse files Browse the repository at this point in the history
fix(session/container): emails with special characters can now be used
  • Loading branch information
IncognitoTGT authored May 16, 2024
2 parents ffea405 + 74f4a1a commit d828d8a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { getAuthSession } from "../auth";
import { revalidatePath } from "next/cache";
import { consola } from "consola";
const getRandomNumber = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min;
const encodeEmailLocal = (email: string) =>
Array.from(email)
.map((char) => (/[a-zA-Z0-9_.-]/.test(char) ? char : char.charCodeAt(0)))
.join("");
/**
* Creates a new Stardust session
* @param Image Docker image to use for making the session
Expand All @@ -32,7 +36,7 @@ async function createSession(Image: string) {
}
const container = await docker
.createContainer({
name: `stardust-${Date.now()}-${userSession.user.email?.split("@")[0]}`,
name: `stardust-${Date.now()}-${encodeEmailLocal((userSession.user?.email as string).split("@")[0])}`,
Image,
HostConfig: {
PortBindings: {
Expand Down

0 comments on commit d828d8a

Please sign in to comment.