mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-03 17:44:44 +02:00
Merge branch 'main' of https://github.com/fosrl/pangolin
This commit is contained in:
commit
3a52615e3e
11 changed files with 82 additions and 18 deletions
15
bruno/Auth/verify-user.bru
Normal file
15
bruno/Auth/verify-user.bru
Normal file
|
@ -0,0 +1,15 @@
|
|||
meta {
|
||||
name: verify-user
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
get {
|
||||
url: http://localhost:3000/badger/verify-user?sessionId=asdf
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
params:query {
|
||||
sessionId: asdf
|
||||
}
|
11
bruno/Traefik/traefik-config.bru
Normal file
11
bruno/Traefik/traefik-config.bru
Normal file
|
@ -0,0 +1,11 @@
|
|||
meta {
|
||||
name: traefik-config
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: http://localhost:3000/api/v1/traefik-config
|
||||
body: none
|
||||
auth: none
|
||||
}
|
|
@ -27,9 +27,10 @@ export const lucia = new Lucia(adapter, {
|
|||
name: "session",
|
||||
expires: false,
|
||||
attributes: {
|
||||
secure: environment.ENVIRONMENT === "prod",
|
||||
sameSite: "strict",
|
||||
// domain: "example.com"
|
||||
// secure: environment.ENVIRONMENT === "prod",
|
||||
// sameSite: "strict",
|
||||
secure: false,
|
||||
domain: ".testing123.io"
|
||||
},
|
||||
},
|
||||
sessionExpiresIn: new TimeSpan(2, "w"),
|
||||
|
|
|
@ -23,12 +23,11 @@ const handle = app.getRequestHandler();
|
|||
const externalPort = environment.EXTERNAL_PORT;
|
||||
const internalPort = environment.INTERNAL_PORT;
|
||||
|
||||
app.prepare().then(() => {
|
||||
|
||||
app.prepare().then(() => {
|
||||
|
||||
|
||||
// External server
|
||||
const externalServer = express();
|
||||
externalServer.set("trust proxy", 1);
|
||||
|
||||
// externalServer.use(helmet()); // Disabled because causes issues with Next.js
|
||||
externalServer.use(cors());
|
||||
|
|
|
@ -10,6 +10,7 @@ import createHttpError from "http-errors";
|
|||
import { z } from "zod";
|
||||
import { fromError } from "zod-validation-error";
|
||||
import { verifyTotpCode } from "@server/auth/2fa";
|
||||
import logger from "@server/logger";
|
||||
|
||||
export const loginBodySchema = z.object({
|
||||
email: z.string().email(),
|
||||
|
@ -116,9 +117,11 @@ export async function login(
|
|||
}
|
||||
|
||||
const session = await lucia.createSession(existingUser.id, {});
|
||||
const cookie = lucia.createSessionCookie(session.id).serialize();
|
||||
logger.debug("Session cookie", JSON.stringify(cookie, null, 2));
|
||||
res.appendHeader(
|
||||
"Set-Cookie",
|
||||
lucia.createSessionCookie(session.id).serialize(),
|
||||
cookie
|
||||
);
|
||||
|
||||
if (!existingUser.emailVerified) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import createHttpError from "http-errors";
|
|||
import { z } from "zod";
|
||||
import { fromError } from "zod-validation-error";
|
||||
import { response } from "@server/utils/response";
|
||||
import logger from "@server/logger";
|
||||
|
||||
export const verifyUserBody = z.object({
|
||||
sessionId: z.string(),
|
||||
|
@ -23,6 +24,8 @@ export async function verifyUser(
|
|||
): Promise<any> {
|
||||
const parsedBody = verifyUserBody.safeParse(req.query);
|
||||
|
||||
logger.debug("Parsed body", parsedBody);
|
||||
|
||||
if (!parsedBody.success) {
|
||||
return next(
|
||||
createHttpError(
|
||||
|
@ -37,6 +40,9 @@ export async function verifyUser(
|
|||
try {
|
||||
const { session, user } = await lucia.validateSession(sessionId);
|
||||
|
||||
logger.debug("Session", session);
|
||||
logger.debug("User", user);
|
||||
|
||||
if (!session || !user) {
|
||||
return next(
|
||||
createHttpError(HttpCode.UNAUTHORIZED, "Invalid session"),
|
||||
|
|
|
@ -24,6 +24,6 @@ gerbilRouter.post("/receive-bandwidth", gerbil.receiveBandwidth);
|
|||
const badgerRouter = Router();
|
||||
internalRouter.use("/badger", badgerRouter);
|
||||
|
||||
internalRouter.get("/verify-user", badger.verifyUser)
|
||||
badgerRouter.get("/verify-user", badger.verifyUser)
|
||||
|
||||
export default internalRouter;
|
||||
|
|
|
@ -6,6 +6,7 @@ import { and, like, eq } from "drizzle-orm";
|
|||
import logger from "@server/logger";
|
||||
import HttpCode from "@server/types/HttpCode";
|
||||
import env from "@server/environment";
|
||||
import environment from "@server/environment";
|
||||
|
||||
export async function traefikConfigProvider(_: Request, res: Response) {
|
||||
try {
|
||||
|
@ -31,14 +32,35 @@ export function buildTraefikConfig(
|
|||
}
|
||||
|
||||
const http: DynamicTraefikConfig["http"] = {
|
||||
routers: {},
|
||||
services: {},
|
||||
routers: {
|
||||
"themainwebpage": {
|
||||
"entryPoints": [
|
||||
"http"
|
||||
],
|
||||
"middlewares": [
|
||||
],
|
||||
"service": "service-themainwebpage",
|
||||
"rule": "Host(`testing123.io`)"
|
||||
},
|
||||
},
|
||||
services: {
|
||||
"service-themainwebpage": {
|
||||
"loadBalancer": {
|
||||
"servers": [
|
||||
{
|
||||
"url": `http://${environment.APP_NAME.toLowerCase()}:3000`
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
middlewares: {
|
||||
[middlewareName]: {
|
||||
plugin: {
|
||||
[middlewareName]: {
|
||||
apiBaseUrl: "http://localhost:3001/api/v1",
|
||||
appBaseUrl: env.BASE_URL,
|
||||
apiBaseUrl: `http://${environment.APP_NAME.toLowerCase()}:3001/api/v1`,
|
||||
// appBaseUrl: env.BASE_URL,
|
||||
appBaseUrl: "http://testing123.io:8081",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -2,8 +2,17 @@ import axios from "axios";
|
|||
|
||||
// const baseURL = `${window.location.protocol}//${window.location.host}/api/v1`;
|
||||
|
||||
|
||||
export const api = axios.create({
|
||||
baseURL: "http://localhost:3000/api/v1",
|
||||
baseURL: "http://testing123.io:8081/api/v1",
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
export const internal = axios.create({
|
||||
baseURL: "http://pangolin:3000/api/v1",
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
|
|
@ -2,7 +2,7 @@ import LoginForm from "@app/components/LoginForm";
|
|||
import { verifySession } from "@app/lib/verifySession";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function Page({
|
||||
export default async function Page({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: { [key: string]: string | string[] | undefined };
|
||||
|
@ -19,5 +19,3 @@ export async function Page({
|
|||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Page;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import api from "@app/api";
|
||||
import { internal } from "@app/api";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function verifySession() {
|
||||
const sessionId = cookies().get("session")?.value ?? null;
|
||||
|
||||
try {
|
||||
const res = await api.get("/user", {
|
||||
await internal.get("/user", {
|
||||
headers: {
|
||||
Cookie: `session=${sessionId}`
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue