SSO token caching and retrieval in CachePool (#4931)

* feat: Implement SSO token caching and retrieval in CachePool

This implementation improves the authentication process by securely caching SSO tokens and managing user sessions.

* Removed commented code

* feat: add deleteSSOTokenCache in ssoSuccess

---------

Co-authored-by: Ong Chung Yau <33013947+chungyau97@users.noreply.github.com>
Co-authored-by: chungyau97 <chungyau97@gmail.com>
This commit is contained in:
Vinod Kiran
2025-07-25 00:44:46 +05:30
committed by GitHub
parent 00342bde88
commit d272683a98
6 changed files with 96 additions and 16 deletions
+3 -1
View File
@@ -6,9 +6,11 @@ const login = (body) => client.post(`/auth/login`, body)
// permissions
const getAllPermissions = () => client.get(`/auth/permissions`)
const ssoSuccess = (token) => client.get(`/auth/sso-success?token=${token}`)
export default {
resolveLogin,
login,
getAllPermissions
getAllPermissions,
ssoSuccess
}
+21 -11
View File
@@ -2,26 +2,36 @@ import { useEffect } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { store } from '@/store'
import { loginSuccess } from '@/store/reducers/authSlice'
import authApi from '@/api/auth'
const SSOSuccess = () => {
const location = useLocation()
const navigate = useNavigate()
useEffect(() => {
// Parse the "user" query parameter from the URL
const queryParams = new URLSearchParams(location.search)
const userData = queryParams.get('user')
const run = async () => {
const queryParams = new URLSearchParams(location.search)
const token = queryParams.get('token')
if (userData) {
// Decode the user data and save it to the state
try {
const parsedUser = JSON.parse(decodeURIComponent(userData))
store.dispatch(loginSuccess(parsedUser))
navigate('/chatflows')
} catch (error) {
console.error('Failed to parse user data:', error)
if (token) {
try {
const user = await authApi.ssoSuccess(token)
if (user) {
if (user.status === 200) {
store.dispatch(loginSuccess(user.data))
navigate('/chatflows')
} else {
navigate('/login')
}
} else {
navigate('/login')
}
} catch (error) {
navigate('/login')
}
}
}
run()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [location.search])