@myrjfa/state 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +18 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -18
- package/dist/lib/actions/actions.d.ts +189 -170
- package/dist/lib/actions/actions.d.ts.map +1 -1
- package/dist/lib/actions/actions.js +347 -307
- package/dist/lib/actions/auth.d.ts +12 -2
- package/dist/lib/actions/auth.d.ts.map +1 -1
- package/dist/lib/actions/fetcher.d.ts +0 -3
- package/dist/lib/actions/fetcher.d.ts.map +1 -1
- package/dist/lib/actions/fetcher.js +122 -84
- package/dist/lib/actions/{severActions.d.ts → serverActions.d.ts} +1 -1
- package/dist/lib/actions/serverActions.d.ts.map +1 -0
- package/dist/lib/actions/{severActions.js → serverActions.js} +3 -0
- package/dist/lib/authSessionManager.d.ts.map +1 -1
- package/dist/lib/authSessionManager.js +41 -34
- package/dist/lib/context/ChatContext.d.ts +1 -1
- package/dist/lib/context/ChatContext.d.ts.map +1 -1
- package/dist/lib/context/ChatContext.js +338 -338
- package/dist/lib/models/blog.d.ts +3 -2
- package/dist/lib/models/blog.d.ts.map +1 -1
- package/dist/lib/models/{notfications.d.ts → notifications.d.ts} +94 -94
- package/dist/lib/models/notifications.d.ts.map +1 -0
- package/dist/lib/models/opportunities/freelance.d.ts +48 -20
- package/dist/lib/models/opportunities/freelance.d.ts.map +1 -1
- package/dist/lib/models/opportunities/internship.d.ts +48 -20
- package/dist/lib/models/opportunities/internship.d.ts.map +1 -1
- package/dist/lib/models/opportunities/job.d.ts +58 -30
- package/dist/lib/models/opportunities/job.d.ts.map +1 -1
- package/dist/lib/models/opportunities/opportunity.d.ts +61 -33
- package/dist/lib/models/opportunities/opportunity.d.ts.map +1 -1
- package/dist/lib/models/opportunities/opportunity.js +1 -0
- package/dist/lib/models/opportunities/volunteerJob.d.ts +48 -20
- package/dist/lib/models/opportunities/volunteerJob.d.ts.map +1 -1
- package/dist/lib/models/portfolio.d.ts +42 -42
- package/dist/lib/models/props.d.ts +21 -4
- package/dist/lib/models/props.d.ts.map +1 -1
- package/dist/lib/models/tile.d.ts +28 -28
- package/dist/lib/models/user.d.ts +19 -4
- package/dist/lib/models/user.d.ts.map +1 -1
- package/dist/lib/models/user.js +5 -0
- package/dist/lib/userAtom.d.ts +218 -198
- package/dist/lib/userAtom.d.ts.map +1 -1
- package/dist/lib/userAtom.js +129 -127
- package/dist/lib/utils.js +4 -4
- package/package.json +3 -1
- package/dist/lib/actions/property.d.ts +0 -77
- package/dist/lib/actions/property.d.ts.map +0 -1
- package/dist/lib/actions/property.js +0 -133
- package/dist/lib/actions/severActions.d.ts.map +0 -1
- package/dist/lib/actions.d.ts +0 -141
- package/dist/lib/actions.d.ts.map +0 -1
- package/dist/lib/actions.js +0 -307
- package/dist/lib/auth.d.ts +0 -150
- package/dist/lib/auth.d.ts.map +0 -1
- package/dist/lib/auth.js +0 -125
- package/dist/lib/fetcher.d.ts +0 -9
- package/dist/lib/fetcher.d.ts.map +0 -1
- package/dist/lib/fetcher.js +0 -84
- package/dist/lib/models/notfications.d.ts.map +0 -1
- package/dist/lib/models/property.d.ts +0 -79
- package/dist/lib/models/property.d.ts.map +0 -1
- package/dist/lib/models/property.js +0 -134
- package/dist/lib/models/volunteerJob.d.ts +0 -398
- package/dist/lib/models/volunteerJob.d.ts.map +0 -1
- package/dist/lib/models/volunteerJob.js +0 -152
- package/dist/lib/severActions.d.ts +0 -3
- package/dist/lib/severActions.d.ts.map +0 -1
- package/dist/lib/severActions.js +0 -19
- package/dist/lib/socket.d.ts +0 -7
- package/dist/lib/socket.d.ts.map +0 -1
- package/dist/lib/socket.js +0 -22
- /package/dist/lib/models/{notfications.js → notifications.js} +0 -0
|
@@ -33,7 +33,7 @@ export declare function signIn(formData: {
|
|
|
33
33
|
accessToken?: string | undefined;
|
|
34
34
|
refreshToken?: string | undefined;
|
|
35
35
|
verifiedIdCard?: boolean | undefined;
|
|
36
|
-
socialLinks?: Record<
|
|
36
|
+
socialLinks?: Partial<Record<"instagram" | "linkedin" | "youtube" | "googleBusiness", string>> | undefined;
|
|
37
37
|
userResume?: string | undefined;
|
|
38
38
|
skills?: {
|
|
39
39
|
skill: string;
|
|
@@ -50,6 +50,11 @@ export declare function signIn(formData: {
|
|
|
50
50
|
gstNumber?: string | undefined;
|
|
51
51
|
panCard?: string | undefined;
|
|
52
52
|
verifiedBusiness?: "true" | "false" | "inProgress" | undefined;
|
|
53
|
+
businessDocument?: string | undefined;
|
|
54
|
+
businessIdType?: "PAN" | "GST" | "Udyam" | "PersonalPAN" | undefined;
|
|
55
|
+
businessIdNumber?: string | undefined;
|
|
56
|
+
businessApiVerificationStatus?: "pending" | "verified" | "failed" | undefined;
|
|
57
|
+
businessVerificationDenialReason?: string | undefined;
|
|
53
58
|
};
|
|
54
59
|
message: string;
|
|
55
60
|
success?: undefined;
|
|
@@ -98,7 +103,7 @@ export declare function verifyEmailOtp(email: string, otp: string, role: "user"
|
|
|
98
103
|
accessToken?: string | undefined;
|
|
99
104
|
refreshToken?: string | undefined;
|
|
100
105
|
verifiedIdCard?: boolean | undefined;
|
|
101
|
-
socialLinks?: Record<
|
|
106
|
+
socialLinks?: Partial<Record<"instagram" | "linkedin" | "youtube" | "googleBusiness", string>> | undefined;
|
|
102
107
|
userResume?: string | undefined;
|
|
103
108
|
skills?: {
|
|
104
109
|
skill: string;
|
|
@@ -115,6 +120,11 @@ export declare function verifyEmailOtp(email: string, otp: string, role: "user"
|
|
|
115
120
|
gstNumber?: string | undefined;
|
|
116
121
|
panCard?: string | undefined;
|
|
117
122
|
verifiedBusiness?: "true" | "false" | "inProgress" | undefined;
|
|
123
|
+
businessDocument?: string | undefined;
|
|
124
|
+
businessIdType?: "PAN" | "GST" | "Udyam" | "PersonalPAN" | undefined;
|
|
125
|
+
businessIdNumber?: string | undefined;
|
|
126
|
+
businessApiVerificationStatus?: "pending" | "verified" | "failed" | undefined;
|
|
127
|
+
businessVerificationDenialReason?: string | undefined;
|
|
118
128
|
};
|
|
119
129
|
message: string;
|
|
120
130
|
success?: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/auth.ts"],"names":[],"mappings":"AAGA,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CAChB
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/auth.ts"],"names":[],"mappings":"AAGA,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAeA;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAa9G;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAcrF;AAED,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAgBzI;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAgBzJ;AAED,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAgBlJ;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAevG"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
type FetchMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
2
|
-
export declare function refreshToken<T>(input: string, method: FetchMethod, body?: any): Promise<T>;
|
|
3
1
|
export declare function get<T>(url: string, includeAuth?: boolean): Promise<T>;
|
|
4
2
|
export declare function post<T>(url: string, body: any): Promise<T>;
|
|
5
3
|
export declare function put<T>(url: string, body: any): Promise<T>;
|
|
6
4
|
export declare function patch<T>(url: string, body: any): Promise<T>;
|
|
7
5
|
export declare function del<T>(url: string, body?: any): Promise<T>;
|
|
8
|
-
export {};
|
|
9
6
|
//# sourceMappingURL=fetcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/fetcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/fetcher.ts"],"names":[],"mapp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|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
import { getCookieHeader, getRole } from "./serverActions";
|
|
2
|
+
// Custom API error class — do NOT import from next/dist internals
|
|
3
|
+
class ApiError extends Error {
|
|
4
|
+
constructor(statusCode, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.statusCode = statusCode;
|
|
7
|
+
this.name = 'ApiError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const baseURL = process.env.NEXT_PUBLIC_API_URL;
|
|
11
|
+
/**
|
|
12
|
+
* #2 — Stable device fingerprint stored in localStorage.
|
|
13
|
+
* Survives browser sessions (unlike cookies which can expire/be cleared).
|
|
14
|
+
* Generated once per browser using crypto.randomUUID().
|
|
15
|
+
*/
|
|
16
|
+
function getOrCreateDeviceId() {
|
|
17
|
+
if (typeof window === 'undefined')
|
|
18
|
+
return null; // SSR guard
|
|
19
|
+
try {
|
|
20
|
+
let deviceId = localStorage.getItem('_trippeaze_device_id');
|
|
21
|
+
if (!deviceId) {
|
|
22
|
+
deviceId = crypto.randomUUID();
|
|
23
|
+
localStorage.setItem('_trippeaze_device_id', deviceId);
|
|
24
|
+
}
|
|
25
|
+
return deviceId;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function customFetch(input, method, body, options = {}) {
|
|
32
|
+
const { includeAuth = false, retry = true } = options;
|
|
33
|
+
const url = `${baseURL}${input}`;
|
|
34
|
+
const isFormData = typeof FormData !== 'undefined' && body instanceof FormData;
|
|
35
|
+
let headers = isFormData
|
|
36
|
+
? { Accept: 'application/json' }
|
|
37
|
+
: { 'Content-Type': 'application/json', Accept: 'application/json' };
|
|
38
|
+
// #2: Attach stable device ID so backend can correctly identify the same browser
|
|
39
|
+
const deviceId = getOrCreateDeviceId();
|
|
40
|
+
if (deviceId) {
|
|
41
|
+
headers['X-Device-Id'] = deviceId;
|
|
42
|
+
}
|
|
43
|
+
if (includeAuth) {
|
|
44
|
+
try {
|
|
45
|
+
const cookieHeader = await getCookieHeader();
|
|
46
|
+
headers = { ...headers, Cookie: cookieHeader };
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error && typeof error === 'object' && ('$$typeof' in error || error.digest === 'DYNAMIC_SERVER_USAGE')) {
|
|
50
|
+
throw error; // Re-throw Next.js PPR bail-out
|
|
51
|
+
}
|
|
52
|
+
// If we can't get cookies (CSR context), credentials: 'include' will handle it
|
|
53
|
+
console.warn('Could not get cookies for auth header:', error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const init = {
|
|
57
|
+
method,
|
|
58
|
+
credentials: 'include',
|
|
59
|
+
headers,
|
|
60
|
+
...(body ? { body: isFormData ? body : JSON.stringify(body) } : {}),
|
|
61
|
+
};
|
|
62
|
+
const response = await fetch(url, init);
|
|
63
|
+
if (response.ok) {
|
|
64
|
+
return response.status !== 204 ? (await response.json()) : {};
|
|
65
|
+
}
|
|
66
|
+
// Token refresh logic on 401 (only for authenticated requests)
|
|
67
|
+
if (response.status === 401 && retry && includeAuth && !input.includes('/login')) {
|
|
68
|
+
return await refreshToken(input, method, body);
|
|
69
|
+
}
|
|
70
|
+
// Error handling
|
|
71
|
+
let errorBody;
|
|
72
|
+
try {
|
|
73
|
+
errorBody = (await response.json());
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
errorBody = {
|
|
77
|
+
statusCode: response.status,
|
|
78
|
+
error: typeof error === 'string' ? error : 'Unknown error',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
throw new ApiError(errorBody.statusCode, errorBody.error);
|
|
82
|
+
}
|
|
83
|
+
// Token refresh function — internal only, not exported
|
|
84
|
+
async function refreshToken(input, method, body) {
|
|
85
|
+
const role = await getRole();
|
|
86
|
+
try {
|
|
87
|
+
const roleForEndpoint = role == "admin" ? "user" : role;
|
|
88
|
+
const response = await fetch(`${baseURL}/${roleForEndpoint}s/refresh-token`, {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
credentials: 'include',
|
|
91
|
+
});
|
|
92
|
+
const data = await response.json();
|
|
93
|
+
if (response.ok) {
|
|
94
|
+
return customFetch(input, method, body, { includeAuth: true, retry: false });
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
throw { statusCode: 401, error: data.error };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error && typeof error === 'object' && ('$$typeof' in error || error.digest === 'DYNAMIC_SERVER_USAGE')) {
|
|
102
|
+
throw error; // Re-throw Next.js PPR bail-out
|
|
103
|
+
}
|
|
104
|
+
throw new ApiError(error.statusCode ?? 500, error.error || error.message || 'Unknown error');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// ✅ Server-safe exported functions
|
|
108
|
+
export async function get(url, includeAuth = true) {
|
|
109
|
+
return customFetch(url, 'GET', undefined, { includeAuth });
|
|
110
|
+
}
|
|
111
|
+
export async function post(url, body) {
|
|
112
|
+
return customFetch(url, 'POST', body, { includeAuth: true });
|
|
113
|
+
}
|
|
114
|
+
export async function put(url, body) {
|
|
115
|
+
return customFetch(url, 'PUT', body, { includeAuth: true });
|
|
116
|
+
}
|
|
117
|
+
export async function patch(url, body) {
|
|
118
|
+
return customFetch(url, 'PATCH', body, { includeAuth: true });
|
|
119
|
+
}
|
|
120
|
+
export async function del(url, body) {
|
|
121
|
+
return customFetch(url, 'DELETE', body, { includeAuth: true });
|
|
122
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverActions.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/serverActions.ts"],"names":[],"mappings":"AAKA,wBAAsB,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,CAKvD;AAED,wBAAsB,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWtD"}
|
|
@@ -13,6 +13,9 @@ export async function getRole() {
|
|
|
13
13
|
return (role && validRoles.includes(role)) ? role : null;
|
|
14
14
|
}
|
|
15
15
|
catch (err) {
|
|
16
|
+
if (err && typeof err === 'object' && ('$$typeof' in err || err.digest === 'DYNAMIC_SERVER_USAGE')) {
|
|
17
|
+
throw err;
|
|
18
|
+
}
|
|
16
19
|
console.error('Invalid token', err);
|
|
17
20
|
return null;
|
|
18
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authSessionManager.d.ts","sourceRoot":"","sources":["../../src/lib/authSessionManager.tsx"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,UAAU,kBAAkB,
|
|
1
|
+
{"version":3,"file":"authSessionManager.d.ts","sourceRoot":"","sources":["../../src/lib/authSessionManager.tsx"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,UAAU,kBAAkB,SAqCzC"}
|
|
@@ -1,34 +1,41 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useAtom } from 'jotai'; // Import useSetAtom
|
|
3
|
-
import { useEffect } from 'react';
|
|
4
|
-
import { useQuery } from '@tanstack/react-query';
|
|
5
|
-
import { initializeAuthSessionAtom
|
|
6
|
-
import { validateSession } from './actions/auth';
|
|
7
|
-
export default function AuthSessionManager() {
|
|
8
|
-
const [, initializeAuthSession] = useAtom(initializeAuthSessionAtom);
|
|
9
|
-
// --- Initial Session Load ---
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
initializeAuthSession();
|
|
12
|
-
}, [initializeAuthSession]);
|
|
13
|
-
// --- Continuous Background Re-validation ---
|
|
14
|
-
const { isError } = useQuery({
|
|
15
|
-
queryKey: ['session'],
|
|
16
|
-
queryFn: validateSession,
|
|
17
|
-
// --- Configuration for a seamless experience ---
|
|
18
|
-
refetchOnWindowFocus: true,
|
|
19
|
-
refetchOnReconnect: true,
|
|
20
|
-
retry: (failureCount, error) => {
|
|
21
|
-
if (error.response?.status === 401)
|
|
22
|
-
return false;
|
|
23
|
-
return failureCount < 2;
|
|
24
|
-
},
|
|
25
|
-
staleTime: 15 * 60 * 1000,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
import { useAtom } from 'jotai'; // Import useSetAtom
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { useQuery } from '@tanstack/react-query';
|
|
5
|
+
import { initializeAuthSessionAtom } from './userAtom'; // Import the atom itself
|
|
6
|
+
import { validateSession } from './actions/auth';
|
|
7
|
+
export default function AuthSessionManager() {
|
|
8
|
+
const [, initializeAuthSession] = useAtom(initializeAuthSessionAtom);
|
|
9
|
+
// --- Initial Session Load ---
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
initializeAuthSession();
|
|
12
|
+
}, [initializeAuthSession]);
|
|
13
|
+
// --- Continuous Background Re-validation ---
|
|
14
|
+
const { isError } = useQuery({
|
|
15
|
+
queryKey: ['session'],
|
|
16
|
+
queryFn: validateSession,
|
|
17
|
+
// --- Configuration for a seamless experience ---
|
|
18
|
+
refetchOnWindowFocus: true,
|
|
19
|
+
refetchOnReconnect: true,
|
|
20
|
+
retry: (failureCount, error) => {
|
|
21
|
+
if (error.response?.status === 401)
|
|
22
|
+
return false;
|
|
23
|
+
return failureCount < 2;
|
|
24
|
+
},
|
|
25
|
+
staleTime: 15 * 60 * 1000,
|
|
26
|
+
});
|
|
27
|
+
// NOTE: We intentionally do NOT reset auth state on isError here.
|
|
28
|
+
// A failed background session ping could be due to:
|
|
29
|
+
// - Backend temporarily down
|
|
30
|
+
// - Network issue
|
|
31
|
+
// - Wrong role endpoint (hosts vs users)
|
|
32
|
+
// The fetcher's refreshToken logic already handles 401s transparently.
|
|
33
|
+
// Aggressively resetting here was causing false logouts after browser restart.
|
|
34
|
+
// useEffect(() => {
|
|
35
|
+
// if (isError) {
|
|
36
|
+
// console.log("Session validation failed. Logging out.");
|
|
37
|
+
// resetAuthState();
|
|
38
|
+
// }
|
|
39
|
+
// }, [isError, resetAuthState]);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { Socket } from "socket.io-client";
|
|
3
3
|
import type { Conversation, Message } from "../models/chat";
|
|
4
|
-
import type { Notif } from "../models/
|
|
4
|
+
import type { Notif } from "../models/notifications";
|
|
5
5
|
interface ChatContextType {
|
|
6
6
|
socket: Socket | null;
|
|
7
7
|
isConnected: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatContext.d.ts","sourceRoot":"","sources":["../../../src/lib/context/ChatContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8E,MAAM,OAAO,CAAC;AACnG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ChatContext.d.ts","sourceRoot":"","sources":["../../../src/lib/context/ChatContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8E,MAAM,OAAO,CAAC;AACnG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAMrD,UAAU,eAAe;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,C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