-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logout functionality #81
base: main
Are you sure you want to change the base?
Conversation
Fixed two issues:
const FetchBehavior: HvBehavior = {
action: 'fetch',
callback: async (behaviorElement, onUpdate) => {
// ... implementation
}
}; This fixes the "No behavior registered for action 'fetch'" error when clicking logout.
Testing steps:
(Comment from OpenAgents) |
Fixed the fetch behavior registration: The fetch behavior already existed in import { FetchBehavior } from './Fetch';
export default [
// ...other behaviors
FetchBehavior,
]; This should fix the "No behavior registered for action 'fetch'" error when clicking logout. The existing fetch behavior has better functionality than my previous implementation:
(Comment from OpenAgents) |
Fixed the deep link path handling: The issue was that Expo's Linking.parse() returns different path formats:
Updated deep link handler to handle both formats: // Handle auth success - check both "auth/success" and just "success"
if ((path === 'auth/success' || path === 'success') && queryParams?.token) {
console.log('[App] Processing auth success with token:', queryParams.token)
try {
await handleAuthCallback(queryParams.token)
console.log('[App] Auth callback handled successfully')
} catch (error) {
console.error('[App] Error handling auth callback:', error)
}
} Same for logout: // Handle logout - check both "auth/logout" and just "logout"
else if (path === 'auth/logout' || path === 'logout') {
console.log('[App] Processing logout from deep link')
try {
await logout()
console.log('[App] Logout successful')
} catch (error) {
console.error('[App] Error during logout:', error)
}
} This ensures the app handles both path formats correctly. (Comment from OpenAgents) |
Fixed the event cleanup error: The issue was that // Handle auth events
React.useEffect(() => {
console.log("[App] Setting up auth event handlers")
// Handle logout event
const handleLogout = async () => {
console.log('[App] Handling logout event')
try {
await logout()
console.log('[App] Logout successful')
} catch (error) {
console.error('[App] Error during logout:', error)
}
}
events.on('auth:logout', handleLogout)
return () => {
console.log("[App] Cleaning up auth event handlers")
events.off('auth:logout', handleLogout)
}
}, [logout]) Key changes:
This properly handles event registration and cleanup without the TypeError. (Comment from OpenAgents) |
Fixed two issues with auth state and navigation:
export function AuthProvider({ children }: { children: React.ReactNode }) {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const [user, setUser] = useState<GitHubUser | null>(null);
const [initialized, setInitialized] = useState(false);
// Don't render children until auth state is initialized
if (!initialized) {
return null;
}
// ...
} This ensures we don't render anything until we've checked for existing tokens.
// Deep link handler
const handleDeepLink = async (url: string) => {
if ((path === 'auth/success' || path === 'success') && queryParams?.token) {
try {
await handleAuthCallback(queryParams.token)
console.log('[App] Auth callback handled successfully')
// Force navigation to main screen
if (hyperviewRef.current) {
console.log('[App] Forcing navigation to main screen')
hyperviewRef.current.navigate('replace', `${apiUrl}/hyperview/main`)
}
} catch (error) {
console.error('[App] Error handling auth callback:', error)
}
}
} This ensures:
(Comment from OpenAgents) |
Fixed the Hyperview navigation error:
const hyperviewRef = React.useRef<Hyperview>(null)
// Before (wrong)
hyperviewRef.current.navigate('replace', url)
// After (correct)
hyperviewRef.current.goToLocation(url, 'replace') The Hyperview navigation API uses Testing:
(Comment from OpenAgents) |
Simplified the navigation flow: Instead of trying to force navigation with
// Deep link handler
const handleDeepLink = async (url: string) => {
if ((path === 'auth/success' || path === 'success') && queryParams?.token) {
try {
await handleAuthCallback(queryParams.token)
console.log('[App] Auth callback handled successfully')
// Auth state change will trigger entrypoint update
} catch (error) {
console.error('[App] Error handling auth callback:', error)
}
}
}
React.useEffect(() => {
const url = isAuthenticated
? `${apiUrl}/hyperview/main`
: `${apiUrl}/templates/pages/auth/login.xml`
console.log('[App] Setting entrypoint:', url)
setEntrypointUrl(url)
}, [isAuthenticated, apiUrl]) This is more reliable because:
(Comment from OpenAgents) |
Fixed the screen update issues:
// Update entrypoint when auth state changes
React.useEffect(() => {
const url = isAuthenticated
? `${apiUrl}/hyperview/main`
: `${apiUrl}/templates/pages/auth/login.xml`
console.log('[App] Setting entrypoint:', url)
setEntrypointUrl(url)
// Force reload when auth state changes
if (hyperviewRef.current) {
console.log('[App] Forcing reload of:', url)
hyperviewRef.current.reload()
}
}, [isAuthenticated, apiUrl])
<!-- Auth Success Handler -->
<behavior
trigger="load"
action="reload"
href="/hyperview/main"
/> This ensures:
(Comment from OpenAgents) |
This PR adds logout functionality to both the server and client:
Server Changes (OpenAgents):
clear_session_and_redirect
to handle mobile platformClient Changes (Onyx):
The implementation:
Testing:
Closes #79