fix: incorrect id type
This commit is contained in:
@@ -21,7 +21,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
const [serverAddress, setServerAddress] = useState<string | null>(null);
|
const [serverAddress, setServerAddress] = useState<string | null>(null);
|
||||||
const [token, setToken] = useState<string | null>(null);
|
const [token, setToken] = useState<string | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [canCreate, setCanCreate] = useState<boolean>(false);
|
const [canCreate, setCanCreate] = useState<boolean | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadAuth();
|
loadAuth();
|
||||||
@@ -77,12 +77,15 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
try {
|
try {
|
||||||
await AsyncStorage.removeItem('auth_token');
|
await AsyncStorage.removeItem('auth_token');
|
||||||
await AsyncStorage.removeItem('auth_user');
|
await AsyncStorage.removeItem('auth_user');
|
||||||
|
await AsyncStorage.removeItem('auth_can_create');
|
||||||
|
|
||||||
api.clearToken();
|
api.clearToken();
|
||||||
api.clearAddress();
|
api.clearAddress();
|
||||||
|
api.clearCanCreate();
|
||||||
setToken(null);
|
setToken(null);
|
||||||
setUser(null);
|
setUser(null);
|
||||||
setServerAddress(null);
|
setServerAddress(null);
|
||||||
|
setCanCreate(null);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to logout', error);
|
console.error('Failed to logout', error);
|
||||||
}
|
}
|
||||||
@@ -96,7 +99,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
token,
|
token,
|
||||||
isAuthenticated: !!token && !!user,
|
isAuthenticated: !!token && !!user,
|
||||||
isLoading,
|
isLoading,
|
||||||
canCreate,
|
canCreate: canCreate === true,
|
||||||
login,
|
login,
|
||||||
logout,
|
logout,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -100,13 +100,17 @@ class UpSnapAPI {
|
|||||||
|
|
||||||
const userID = data.record.id;
|
const userID = data.record.id;
|
||||||
const userPermissionResponse = await fetch(
|
const userPermissionResponse = await fetch(
|
||||||
`${this.address}/collections/permissions/records/${userID}?expand=user,read,update,delete,power`,
|
`${this.address}/collections/permissions/records?filter=(user='${userID}')&expand=user,read,update,delete,power`,
|
||||||
{
|
{
|
||||||
headers: this.getHeaders(),
|
headers: this.getHeaders(),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
if (!userPermissionResponse.ok) {
|
||||||
|
const error = await userPermissionResponse.json();
|
||||||
|
throw new Error(error.message || 'Authentication failed');
|
||||||
|
}
|
||||||
|
|
||||||
const user: PermissionResponse = await userPermissionResponse.json();
|
const user: PermissionResponse = (await userPermissionResponse.json()).items[0];
|
||||||
this.canCreate = user.create;
|
this.canCreate = user.create;
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
Reference in New Issue
Block a user