feat(auth): implement Bearer token fallback in fetchSessionUser for private network HTTP connections
- Expanded fetchSessionUser to include Bearer token from localStorage as a fallback for authentication when Secure cookies fail. - Updated headers to conditionally include Authorization if a token is present. - Ensured compatibility with the recent fix for the Secure cookie flag on private network connections.
This commit is contained in:
@@ -9,12 +9,16 @@ export const AuthProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
||||
const authRequestVersionRef = useRef(0);
|
||||
|
||||
const fetchSessionUser = useCallback(async (): Promise<User> => {
|
||||
const headers: Record<string, string> = { Accept: 'application/json' };
|
||||
const stored = localStorage.getItem('charon_auth_token');
|
||||
if (stored) {
|
||||
headers['Authorization'] = `Bearer ${stored}`;
|
||||
}
|
||||
|
||||
const response = await fetch('/api/v1/auth/me', {
|
||||
method: 'GET',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user