move some functions around

main
samerbam 1 year ago
parent c6cb2aedc2
commit c198341999

@ -313,26 +313,64 @@
// }); // });
// }); // });
// import { createAuth0Client } from '@auth0/auth0-spa-js'; // import { createAuth0Client } from '@auth0/auth0-spa-js';
let jToken = "" // let jToken = ""
function loginAction(e) { // function loginAction(e) {
auth0.createAuth0Client({ // auth0.createAuth0Client({
domain: 'dev-kazsp1tz0e7t5d07.us.auth0.com', // domain: 'dev-kazsp1tz0e7t5d07.us.auth0.com',
clientId: 'Pw2MvNmIAJUA4THZzsZTEeqkXnCTHYr3' // clientId: 'Pw2MvNmIAJUA4THZzsZTEeqkXnCTHYr3'
}).then(a0 => { // }).then(a0 => {
const token = a0.getTokenWithPopup({ // const token = a0.getTokenWithPopup({
authorizationParams: { // authorizationParams: {
audience: 'https://RecieptTodos.imsam.ca', // audience: 'https://RecieptTodos.imsam.ca',
scope: 'todos:all' // scope: 'todos:all'
} // }
}); // });
token.then(t => { // 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") // document.getElementById("loginPanel").classList.add("hidden")
// console.log(t) // console.log(jToken)
jToken = t // // console.log(t)
getTodosFromAPI() // // jToken = t
// document.getElementById("testToken").innerHTML = t // // document.getElementById("testToken").innerHTML = t
// fetch('/api/todos/get?' + new URLSearchParams({ // fetch('/api/todos/get?' + new URLSearchParams({
// date: dayjs().format("YYYY-MM-DD"), // date: dayjs().format("YYYY-MM-DD"),
@ -341,7 +379,7 @@
// withCredentials: true, // withCredentials: true,
// credentials: 'include', // credentials: 'include',
// headers: { // headers: {
// 'Authorization': "Bearer " + t, // 'Authorization': "Bearer " + jToken,
// } // }
// }).then(re => { // }).then(re => {
// re.json().then(jso => { // re.json().then(jso => {
@ -356,48 +394,10 @@
// // console.log(items.json) // // 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 // document.getElementById("loginButton").addEventListener('click', loginAction)
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', (e) => { // document.getElementById("loginButton").addEventListener('click', (e) => {
// auth0.createAuth0Client({ // auth0.createAuth0Client({
// domain: 'dev-kazsp1tz0e7t5d07.us.auth0.com', // domain: 'dev-kazsp1tz0e7t5d07.us.auth0.com',

@ -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="") { function sendPrintRequest(action, date, sentence="") {
console.log(jToken) console.log(jToken)
return fetch("/api/todos/print", { return fetch("/api/todos/print", {

Loading…
Cancel
Save