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