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