Private/Load-DuneSession.ps1

function Load-DuneSession {
    $path = "$env:USERPROFILE\.dune\session.clixml"
    if (Test-Path $path) {
        $script:DuneSession = Import-CliXml -Path $path
        Write-Verbose -Verbose ("Loading cached DuneSession" -f (Get-Item $path).CreationTime.ToShortDateString())
        if ($DuneSession.Type -eq 'Credential') {
            try {
                $null = Get-DuneTenant
            }
            catch {
                Remove-Variable -Name DuneSession -Force
                Write-Warning "Cached session is expired. Please use Connect-Dune to reauthenticate"
            }
        }
        else {
            if ($DuneSession.ExpiryDate -and (Get-Date) -ge $DuneSession.ExpiryDate) {
                if ($DuneSession.Type -eq 'SocialLogin') { Refresh-JwtToken }
            }
        }
    }
}