move some functions around

This commit is contained in:
samerbam 2023-08-24 17:15:32 -04:00
parent c6cb2aedc2
commit c198341999
2 changed files with 162 additions and 73 deletions

View File

@ -313,26 +313,64 @@
// });
// });
// import { createAuth0Client } from '@auth0/auth0-spa-js';
let jToken = ""
// let jToken = ""
function loginAction(e) {
auth0.createAuth0Client({
domain: 'dev-kazsp1tz0e7t5d07.us.auth0.com',
clientId: 'Pw2MvNmIAJUA4THZzsZTEeqkXnCTHYr3'
}).then(a0 => {
const token = a0.getTokenWithPopup({
authorizationParams: {
audience: 'https://RecieptTodos.imsam.ca',
scope: 'todos:all'
}
});
token.then(t => {
// function loginAction(e) {
// auth0.createAuth0Client({
// domain: 'dev-kazsp1tz0e7t5d07.us.auth0.com',
// clientId: 'Pw2MvNmIAJUA4THZzsZTEeqkXnCTHYr3'
// }).then(a0 => {
// const token = a0.getTokenWithPopup({
// authorizationParams: {
// audience: 'https://RecieptTodos.imsam.ca',
// scope: 'todos:all'
// }
// });
// token.then(t => {
// // document.getElementById("loginPanel").classList.add("hidden")
// // console.log(t)
// jToken = t
// getTodosFromAPI()
// // document.getElementById("testToken").innerHTML = t
// // fetch('/api/todos/get?' + new URLSearchParams({
// // date: dayjs().format("YYYY-MM-DD"),
// // }), {
// // method: 'GET',
// // withCredentials: true,
// // credentials: 'include',
// // headers: {
// // 'Authorization': "Bearer " + t,
// // }
// // }).then(re => {
// // re.json().then(jso => {
// // console.log(jso)
// // for (let todo of jso.todos) {
// // console.log(todo)
// // // function addTask(defaultTimeRange="", defaultTaskText="New Task", editable=true) {
// // addTask(defaultTimeRange=todo.time, defaultTaskText=todo.text, editable=false)
// // }
// // })
// // // var items = JSON.parse(re.json())
// // // console.log(items.json)
// // })
// //TODO: Make call with token to backend to load all current todos
// })
// });
// };
// function getTodosFromAPI() {
// document.getElementById("loginPanel").classList.add("hidden")
// console.log(t)
jToken = t
getTodosFromAPI()
// console.log(jToken)
// // console.log(t)
// // jToken = t
// document.getElementById("testToken").innerHTML = t
// // document.getElementById("testToken").innerHTML = t
// fetch('/api/todos/get?' + new URLSearchParams({
// date: dayjs().format("YYYY-MM-DD"),
@ -341,7 +379,7 @@
// withCredentials: true,
// credentials: 'include',
// headers: {
// 'Authorization': "Bearer " + t,
// 'Authorization': "Bearer " + jToken,
// }
// }).then(re => {
// re.json().then(jso => {
@ -356,48 +394,10 @@
// // console.log(items.json)
// })
//TODO: Make call with token to backend to load all current todos
})
});
// //TODO: Make call with token to backend to load all current todos
// }
};
function getTodosFromAPI() {
document.getElementById("loginPanel").classList.add("hidden")
console.log(jToken)
// console.log(t)
// jToken = t
// document.getElementById("testToken").innerHTML = t
fetch('/api/todos/get?' + new URLSearchParams({
date: dayjs().format("YYYY-MM-DD"),
}), {
method: 'GET',
withCredentials: true,
credentials: 'include',
headers: {
'Authorization': "Bearer " + jToken,
}
}).then(re => {
re.json().then(jso => {
console.log(jso)
for (let todo of jso.todos) {
console.log(todo)
// function addTask(defaultTimeRange="", defaultTaskText="New Task", editable=true) {
addTask(defaultTimeRange=todo.time, defaultTaskText=todo.text, editable=false)
}
})
// var items = JSON.parse(re.json())
// console.log(items.json)
})
//TODO: Make call with token to backend to load all current todos
}
document.getElementById("loginButton").addEventListener('click', loginAction)
// document.getElementById("loginButton").addEventListener('click', loginAction)
// document.getElementById("loginButton").addEventListener('click', (e) => {
// auth0.createAuth0Client({
// domain: 'dev-kazsp1tz0e7t5d07.us.auth0.com',

View File

@ -577,6 +577,95 @@ function savePrintButtonListener(e) {
}
let jToken = ""
function loginAction(e) {
auth0.createAuth0Client({
domain: 'dev-kazsp1tz0e7t5d07.us.auth0.com',
clientId: 'Pw2MvNmIAJUA4THZzsZTEeqkXnCTHYr3'
}).then(a0 => {
const token = a0.getTokenWithPopup({
authorizationParams: {
audience: 'https://RecieptTodos.imsam.ca',
scope: 'todos:all'
}
});
token.then(t => {
// document.getElementById("loginPanel").classList.add("hidden")
// console.log(t)
jToken = t
getTodosFromAPI()
// document.getElementById("testToken").innerHTML = t
// fetch('/api/todos/get?' + new URLSearchParams({
// date: dayjs().format("YYYY-MM-DD"),
// }), {
// method: 'GET',
// withCredentials: true,
// credentials: 'include',
// headers: {
// 'Authorization': "Bearer " + t,
// }
// }).then(re => {
// re.json().then(jso => {
// console.log(jso)
// for (let todo of jso.todos) {
// console.log(todo)
// // function addTask(defaultTimeRange="", defaultTaskText="New Task", editable=true) {
// addTask(defaultTimeRange=todo.time, defaultTaskText=todo.text, editable=false)
// }
// })
// // var items = JSON.parse(re.json())
// // console.log(items.json)
// })
//TODO: Make call with token to backend to load all current todos
})
});
};
function getTodosFromAPI() {
document.getElementById("loginPanel").classList.add("hidden")
console.log(jToken)
// console.log(t)
// jToken = t
// document.getElementById("testToken").innerHTML = t
fetch('/api/todos/get?' + new URLSearchParams({
date: dayjs().format("YYYY-MM-DD"),
}), {
method: 'GET',
withCredentials: true,
credentials: 'include',
headers: {
'Authorization': "Bearer " + jToken,
}
}).then(re => {
re.json().then(jso => {
console.log(jso)
for (let todo of jso.todos) {
console.log(todo)
// function addTask(defaultTimeRange="", defaultTaskText="New Task", editable=true) {
addTask(defaultTimeRange=todo.time, defaultTaskText=todo.text, editable=false)
}
})
// var items = JSON.parse(re.json())
// console.log(items.json)
})
//TODO: Make call with token to backend to load all current todos
}
document.getElementById("loginButton").addEventListener('click', loginAction)
function sendPrintRequest(action, date, sentence="") {
console.log(jToken)
return fetch("/api/todos/print", {