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