mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user