Fix dynamic domain on discord API request
This commit is contained in:
parent
43c7e1f5b1
commit
8f9adf2e1b
@ -85,7 +85,7 @@ function redirect(res: ServerResponse, path: string) {
|
|||||||
function login(session: Session, res: ServerResponse) {
|
function login(session: Session, res: ServerResponse) {
|
||||||
if (session.logedIn) return "uzjsi prihlasenej";
|
if (session.logedIn) return "uzjsi prihlasenej";
|
||||||
|
|
||||||
redirect(res, "https://discord.com/api/oauth2/authorize?client_id=1064269692165963826&redirect_uri=http%3A%2F%2F%C5%A1ach.ml%2Foauth&response_type=code&scope=identify");
|
redirect(res, `https://discord.com/api/oauth2/authorize?client_id=1064269692165963826&redirect_uri=http%3A%2F%2F${encodeURIComponent(sachyDomena)}%2Foauth&response_type=code&scope=identify`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout(session: Session, res: ServerResponse) {
|
function logout(session: Session, res: ServerResponse) {
|
||||||
@ -104,7 +104,7 @@ function loginErr(res: ServerResponse) {
|
|||||||
async function overeni(url: string, session: Session, res: ServerResponse) {
|
async function overeni(url: string, session: Session, res: ServerResponse) {
|
||||||
|
|
||||||
const code = (new URL(url, "h:/")).searchParams.get("code");
|
const code = (new URL(url, "h:/")).searchParams.get("code");
|
||||||
const data = await fetch("https://discord.com/api/v10/oauth2/token", { method: "post", body: `client_id=1064269692165963826&client_secret=8HHKODmb1HTLWoJGVyoinSU_9323dEla&grant_type=authorization_code&code=${code}&redirect_uri=http%3A%2F%2F%C5%A1ach.ml%2Foauth`, headers: { "Content-type": "application/x-www-form-urlencoded" } })
|
const data = await fetch("https://discord.com/api/v10/oauth2/token", { method: "post", body: `client_id=1064269692165963826&client_secret=8HHKODmb1HTLWoJGVyoinSU_9323dEla&grant_type=authorization_code&code=${code}&redirect_uri=http%3A%2F%2F${encodeURIComponent(sachyDomena)}%2Foauth`, headers: { "Content-type": "application/x-www-form-urlencoded" } })
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.catch(err => log("sachy jednotka:", err));
|
.catch(err => log("sachy jednotka:", err));
|
||||||
|
|
||||||
@ -154,8 +154,10 @@ const server = createServer((req, res) => {
|
|||||||
// Zpracování tahu
|
// Zpracování tahu
|
||||||
if (url.pathname.length == 2 || url.pathname.length == 4) return validateMove(res, session, req.url!);
|
if (url.pathname.length == 2 || url.pathname.length == 4) return validateMove(res, session, req.url!);
|
||||||
|
|
||||||
|
// Oauth
|
||||||
if (req.url?.startsWith("/oauth")) return overeni(req.url, session, res);
|
if (req.url?.startsWith("/oauth")) return overeni(req.url, session, res);
|
||||||
|
|
||||||
|
// Jinak
|
||||||
switch (url.pathname) {
|
switch (url.pathname) {
|
||||||
case "/": {
|
case "/": {
|
||||||
const response = indexStranka
|
const response = indexStranka
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user