fix: auth working on deployment
This commit is contained in:
parent
f13d1557fb
commit
5c1ef0c7d1
15
api/main.ts
15
api/main.ts
@ -15,8 +15,7 @@ type AppState = {
|
||||
|
||||
const router = new Router<AppState>();
|
||||
|
||||
const hostname = "localhost";
|
||||
const deployHostname = "forums.warabi.co"
|
||||
const hostname = "forums.warabi.co";
|
||||
const authPath = "/auth";
|
||||
const port = 8000;
|
||||
|
||||
@ -42,8 +41,8 @@ export interface SteamUser {
|
||||
}
|
||||
|
||||
export const Steam = new SteamAuth({
|
||||
realm: `http://${hostname}:${port}`,
|
||||
returnUrl: `https://${hostname}:${port}${authPath}/return`,
|
||||
realm: `https://${hostname}`,
|
||||
returnUrl: `https://${hostname}${authPath}/return`,
|
||||
apiKey: Deno.env.get("STEAM_API_KEY"),
|
||||
});
|
||||
|
||||
@ -51,6 +50,7 @@ router.get(`${authPath}/login`, async (ctx) => {
|
||||
try {
|
||||
const redirectUrl = await Steam.getRedirectUrl() as string;
|
||||
ctx.response.body = { url: redirectUrl };
|
||||
console.log("Redirecting to:", redirectUrl);
|
||||
} catch (e) {
|
||||
ctx.response.body = `Error: ${e}`;
|
||||
}
|
||||
@ -58,10 +58,13 @@ router.get(`${authPath}/login`, async (ctx) => {
|
||||
|
||||
router.get(`${authPath}/return`, async (ctx) => {
|
||||
try {
|
||||
console.log("Authenticating user...");
|
||||
const user = await Steam.authenticate(ctx) as SteamUser;
|
||||
console.log(user);
|
||||
ctx.state.session.set("steamid", user.steamid);
|
||||
ctx.state.session.set("user", user);
|
||||
ctx.response.redirect(`https://${deployHostname}/signedIn`);
|
||||
console.log("Authenticated user:", user);
|
||||
ctx.response.redirect("/");
|
||||
} catch (e) {
|
||||
ctx.response.body = `Error: ${e}`;
|
||||
}
|
||||
@ -94,7 +97,7 @@ router.get("/api/dinosaurs/:dinosaur", (context) => {
|
||||
});
|
||||
|
||||
const store = new CookieStore(Deno.env.get("SESSION_COOKIE_KEY") as string, {
|
||||
sessionDataCookieName: "warbforums_sessionData",
|
||||
sessionDataCookieName: "warbforums_sessionData"
|
||||
});
|
||||
|
||||
const app = new Application<AppState>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user