Skip to content

Commit

Permalink
Merge pull request #204 from zstenger93/api_connections
Browse files Browse the repository at this point in the history
I'm stuck in the authception, please save me
  • Loading branch information
zstenger93 authored Jan 6, 2024
2 parents a6b5918 + 7a9d986 commit 70d3033
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
11 changes: 10 additions & 1 deletion backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
# if DEBUG:
# REDIRECT_URI = "http://localhost:8000"
# else:
# REDIRECT_URI = "https://transcendence-backend-znhl.onrender.com"

REDIRECT_URI = "https://transcendence-backend-znhl.onrender.com"

print("DEBUG:", DEBUG)
if DEBUG:
print("DEBUG: True: ", DEBUG)
else:
print("DEBUG: False: ", DEBUG)

# Application definition

Expand Down Expand Up @@ -124,6 +129,10 @@
# }
# }
# else:
# DATABASES = {
# 'default': dj_database_url.parse(os.getenv('DATABASE_URL'))
# }

DATABASES = {
'default': dj_database_url.parse(os.getenv('DATABASE_URL'))
}
Expand Down
2 changes: 0 additions & 2 deletions backend/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
for key, value in os.environ.items():
print(f"{key}: {value}")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
39 changes: 13 additions & 26 deletions frontend/src/components/welcome_page/LoginVia42.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,29 @@ const OAuth = async ({ navigate, redirect_uri }) => {
console.log("OAuth");
console.log(redirect_uri);
const auth = `${redirect_uri}/api/is_authenticated/`;
let response = await fetch(auth, {
let response = await fetch(auth, {
credentials: "include",
});
let data = await response.json();
});

let data = await response.json();

if (!data.is_authenticated) {
const authWindow = window.open(`${redirect_uri}/api/oauth/authorize/`);
while (!authWindow.closed) {
window.open(`${redirect_uri}/api/oauth/authorize/`);
while (!data.is_authenticated) {
await new Promise((resolve) => setTimeout(resolve, 1000));
response = await fetch(auth, {
credentials: "include",
});
data = await response.json();
if (data.is_authenticated) {
console.log("authenticated");
navigate("/home");
authWindow.close();
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;
}
console.log("I'm stuck in authception")
}
console.log(data.is_authenticated);
console.log("authenticated");
navigate("/home");
} else {
navigate("/home");
}
};
};

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

0 comments on commit 70d3033

Please sign in to comment.