Skip to content

Commit

Permalink
Merge pull request #200 from zstenger93/api_connections
Browse files Browse the repository at this point in the history
is_authenticated needs a check
  • Loading branch information
zstenger93 authored Jan 5, 2024
2 parents 43fc5f9 + ecb3f96 commit 738ec65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
5 changes: 0 additions & 5 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import os
import dj_database_url


# postgres://transcendence_db_user:TyO3oKD9ARZQFWRy1TkBoLBOqRy5IlZv@dpg-cm993a7109ks73cilvk0-a/transcendence_db


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand Down Expand Up @@ -148,7 +144,6 @@
},
]

# postgres://transcendence_db_user:TyO3oKD9ARZQFWRy1TkBoLBOqRy5IlZv@dpg-cm993a7109ks73cilvk0-a.frankfurt-postgres.render.com/transcendence_db

# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/
Expand Down
37 changes: 21 additions & 16 deletions frontend/src/components/welcome_page/LoginVia42.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
import React from "react";
import { WelcomeButtonStyle } from "../buttons/ButtonStyle";

let stopFetching = false;

const OAuth = async ({ navigate, redirect_uri }) => {
const auth = `${redirect_uri}/api/is_authenticated/`;
let response, data;

response = await fetch(auth, {
let response = await fetch(auth, {
credentials: "include",
});
data = await response.json();

if (!data.is_authenticated) {
});

let data = await response.json();
// console.log(data);
if (!data.is_authenticated) {
const authWindow = window.open(`${redirect_uri}/api/oauth/authorize/`);

while (!stopFetching) {
while (!authWindow.closed) {
response = await fetch(auth, {
credentials: "include",
});
data = await response.json();

if (data.is_authenticated) {
console.log("authenticated");
stopFetching = true;
navigate("/home");
authWindow.close();
} else {
await new Promise(resolve => setTimeout(resolve, 1000));
break;
}
if (authWindow.closed) {
await new Promise(resolve => setTimeout(resolve, 5000));
response = await fetch(auth, {
credentials: "include",
});
data = await response.json();
console.log(data.is_authenticated);
console.log("authenticated");
navigate("/home");
console.log("closed");
break;
}
}
} else {
navigate("/home");
}
};
};

const LoginButton = ({ t, navigate, redirect_uri }) => {
return (
Expand Down

0 comments on commit 738ec65

Please sign in to comment.