mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-10 09:53:48 +00:00
auth flow
This commit is contained in:
@@ -232,12 +232,9 @@ export async function postNew(initialData: Partial<ProjectData>) {
|
||||
* @description sheet Client File
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const uploadSheetClientFile = async (
|
||||
file: File
|
||||
) => {
|
||||
export const uploadSheetClientFile = async (file: File) => {
|
||||
const formData = new FormData();
|
||||
formData.append('userFile', file);
|
||||
|
||||
await axios
|
||||
.post(`${ontimeURL}/sheet-clientsecrect`, formData, {
|
||||
headers: {
|
||||
@@ -248,4 +245,14 @@ export const uploadSheetClientFile = async (
|
||||
},
|
||||
})
|
||||
.then((response) => response.data.id);
|
||||
};
|
||||
};
|
||||
|
||||
export const getSheetsAuthStatus = async () => {
|
||||
const res = await axios.get(`${ontimeURL}/sheet-authstatus`);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getSheetsAuthUrl = async () => {
|
||||
const res = await axios.get(`${ontimeURL}/sheet-authurl`);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
ModalHeader,
|
||||
ModalOverlay,
|
||||
} from '@chakra-ui/react';
|
||||
import { uploadSheetClientFile } from '../../../common/api/ontimeApi';
|
||||
import { getSheetsAuthStatus, getSheetsAuthUrl, uploadSheetClientFile } from '../../../common/api/ontimeApi';
|
||||
|
||||
interface SheetsModalProps {
|
||||
onClose: () => void;
|
||||
@@ -21,6 +21,7 @@ export default function SheetsModal(props: SheetsModalProps) {
|
||||
const { isOpen, onClose } = props;
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [authState, setAuthState] = useState<boolean>(true);
|
||||
|
||||
const handleClose = () => onClose();
|
||||
const handleClick = () => {
|
||||
@@ -33,13 +34,26 @@ export default function SheetsModal(props: SheetsModalProps) {
|
||||
setFile(null);
|
||||
return;
|
||||
} else {
|
||||
uploadSheetClientFile(selectedFile)
|
||||
uploadSheetClientFile(selectedFile);
|
||||
}
|
||||
setFile(selectedFile);
|
||||
};
|
||||
|
||||
const handleAuthenticate = () => {}
|
||||
const handlePullData = () => {}
|
||||
//TODO: do smoething better here
|
||||
getSheetsAuthStatus().then((data) => {
|
||||
setAuthState(data);
|
||||
});
|
||||
|
||||
const handleAuthenticate = () => {
|
||||
getSheetsAuthUrl().then((data) => {
|
||||
console.log(data);
|
||||
if (data == 'bad') {
|
||||
} else {
|
||||
window.open(data, '_blank', 'noreferrer');
|
||||
}
|
||||
});
|
||||
};
|
||||
const handlePullData = () => {};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
@@ -69,8 +83,8 @@ export default function SheetsModal(props: SheetsModalProps) {
|
||||
<div>
|
||||
<Button onClick={handleClick}>Upload Client Secrect</Button>
|
||||
</div>
|
||||
{file && <div>We got a file</div>}
|
||||
<div>You are authenticated</div>
|
||||
{authState && <div>You are authenticated</div>}
|
||||
{!authState && <div>You are not authenticated</div>}
|
||||
<div>
|
||||
<Button variant='ontime-filled' padding='0 2em' onClick={handlePullData}>
|
||||
Pull data
|
||||
|
||||
@@ -106,3 +106,11 @@ router.post('/new', projectSanitiser, postNew);
|
||||
|
||||
// create route between controller and '/ontime/sheet-client' endpoint
|
||||
router.post('/sheet-clientsecrect', uploadFile, sheetClientFile);
|
||||
|
||||
// create route between controller and '/ontime/sheet-authstatus' endpoint
|
||||
router.get('/sheet-authstatus', sheetAuthState);
|
||||
|
||||
// create route between controller and '/ontime/sheet-authstatus' endpoint
|
||||
router.get('/sheet-authurl', sheetAuthUrl);
|
||||
|
||||
|
||||
|
||||
@@ -143,6 +143,7 @@ class sheet {
|
||||
*/
|
||||
public async openAuthServer(): Promise<string | false> {
|
||||
//TODO: this only works on local networks
|
||||
//FIXME: the authUrl is not returnd before the second call
|
||||
if (sheet.authUrl) {
|
||||
return sheet.authUrl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user