Skip to content

Commit

Permalink
chore: Update wizard form to include cookie authentication check
Browse files Browse the repository at this point in the history
  • Loading branch information
szweibel committed Jul 30, 2024
1 parent 21beea1 commit b37a109
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions pages/wizard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useState } from "react";
import { FormControl, InputLabel, Input } from '@mui/material';
import { Stack, TextField, Button, Container, MenuItem } from '@mui/material';
import useAllWorkshops from '../../components/Hooks/UseAllWorkshops';
import { Add, Remove } from '@mui/icons-material';
import { Add, Cookie, Remove } from '@mui/icons-material';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import CircularProgress from '@mui/material/CircularProgress';
Expand Down Expand Up @@ -78,12 +78,12 @@ export default function Form(props) {
let displayWorkshops = data.workshops.filter(workshop => workshop.type === 'file' && !workshop.name.startsWith('DHRIFT_') && !workshop.name.startsWith('README.md'));
displayWorkshops = displayWorkshops.map(workshop => ({ name: workshop.name.replace('.md', '') }));

useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
setInstCreated(urlParams.get('instCreated') === 'true');
setAuthComplete(urlParams.get('authComplete') === 'true');
}
, []);
// useEffect(() => {
// const urlParams = new URLSearchParams(window.location.search);
// setInstCreated(urlParams.get('instCreated') === 'true');
// setAuthComplete(urlParams.get('authComplete') === 'true');
// }
// , []);

const uploadFiles = async (files) => {
const addAPIURL = APIURL + 'add_file';
Expand Down Expand Up @@ -129,8 +129,7 @@ export default function Form(props) {
function handle_auth_complete(event) {
const data = JSON.parse(event.data);
if (data.auth === 'complete') {
setAuthComplete(true);
createInstitute();
checkAuth();
}
else {
setShowProgress(false);
Expand All @@ -156,22 +155,14 @@ export default function Form(props) {
if (response.ok) {
console.log('Authenticated');
setAuthComplete(true);
createInstitute();
// createInstitute();
}
else {
console.log('Not authenticated');
permRequest();
}
}

const checkAuthSection = (
<div>
<h2>Check Authentication</h2>
<p>Click the button below to check if you are authenticated with GitHub.</p>
<Button onClick={checkAuth}>Check Authentication</Button>
</div>
);

const permRequest = async () => {
console.log('Requesting permissions');
const APIURL = 'https://github.com/login/oauth/authorize?scope=repo, read:user&client_id=b5be98ebcdc9cdf67526&state=' + window.location.origin;
Expand Down Expand Up @@ -784,6 +775,13 @@ export default function Form(props) {
</>
);

const cookieTestButton = (
<>{authComplete ? <div>You are authenticated</div> : <Button onClick={checkAuth}>Check Authentication</Button>}

</>
);


// const thirdStageSection = (
// <>

Expand All @@ -810,6 +808,7 @@ export default function Form(props) {
<div
className='form'
>
{cookieTestButton}
{firstStage && firstStageSection}
{secondStage && secondStageSection}
{/* {thirdStage && thirdStageSection} */}
Expand Down

0 comments on commit b37a109

Please sign in to comment.