import React, { useState } from 'react'; import { useWdkDependenciesEffect, WdkDependencies } from '@veupathdb/wdk-client/lib/Hooks/WdkDependenciesEffect'; import { makeClassNameHelper } from '@veupathdb/wdk-client/lib/Utils/ComponentUtils'; import { alert } from '@veupathdb/wdk-client/lib/Utils/Platform'; import './ResetSession.scss'; const cx = makeClassNameHelper('ebrc-ResetSession') export function ResetSession() { const [ confirmed, setConfirmed ] = useState(false); const [ isResetSessionClicked, setIsResetSessionClicked ] = useState(false); useWdkDependenciesEffect(wdkDependencies => { (async function() { if (isResetSessionClicked) { await resetSession(wdkDependencies); await alert('Your session has been reset', 'You will now be redirected to the home page.'); window.location.href = '/'; } })(); }, [ isResetSessionClicked ]); return (

Reset Session

Clicking the following button will remove all cookies related to this website and redirect you to the homepage.

This means the following things will happen:

setConfirmed(!confirmed)} type="checkbox" id="understand-reset" />
); } function resetSession({ paramValueStore, wdkService }: WdkDependencies) { deleteCookies('/'); deleteCookies('/cgi-bin/'); if (window.sessionStorage) { window.sessionStorage.clear(); } if (window.localStorage) { window.localStorage.clear(); } return Promise.all([ paramValueStore.clearParamValues(), wdkService._clearCache() ]);; } function deleteCookies(path: string) { document.cookie.split(/\s*;\s*/) .forEach(function(cookie) { var eqPos = cookie.indexOf('='); var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; var cookieValue = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT'; if (path) { cookieValue += ';path=' + path; } document.cookie = cookieValue; }); }