|
|
@@ -14,20 +14,16 @@ class AuthenticationService {
|
|
|
email: username,
|
|
|
password: password,
|
|
|
isBinding: isBinding,
|
|
|
-
|
|
|
},
|
|
|
{
|
|
|
- customConfig: {needAuth: true}
|
|
|
+ customConfig: {needAuth: false}
|
|
|
},
|
|
|
);
|
|
|
if (response.status === 201) {
|
|
|
const token = response.data.accessToken;
|
|
|
await SecureStore.setItemAsync('accessToken', token);
|
|
|
- console.log('AccessToken', token);
|
|
|
return true;
|
|
|
} else {
|
|
|
- console.error('Login failed:', response.status);
|
|
|
-
|
|
|
return false;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
@@ -42,35 +38,23 @@ class AuthenticationService {
|
|
|
}
|
|
|
|
|
|
async phoneLogin(username: string | null | undefined, password: string, isBinding?: boolean) {
|
|
|
- try {
|
|
|
- const response = await apiClient.instance.post(
|
|
|
- `/public/client/customer/phone/sign-in`,
|
|
|
- {
|
|
|
- phone: username,
|
|
|
- password: password,
|
|
|
- isBinding: isBinding,
|
|
|
-
|
|
|
- },
|
|
|
- {
|
|
|
-
|
|
|
- customConfig: {needAuth: true}
|
|
|
- }
|
|
|
- );
|
|
|
- if (response.status === 201) {
|
|
|
- const token = response.data.accessToken;
|
|
|
- await SecureStore.setItemAsync('accessToken', token);
|
|
|
- return 'login successful';
|
|
|
- } else {
|
|
|
- return response.data.message;
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
- console.error('Login error:', error.response?.data?.message || error.message);
|
|
|
- return error.response?.data?.message || error.message;
|
|
|
- } else {
|
|
|
- console.error('An unexpected error occurred:', error);
|
|
|
- return 'An unexpected error occurred: ' + error;
|
|
|
+ const response = await apiClient.instance.post(
|
|
|
+ `/public/client/customer/phone/sign-in`,
|
|
|
+ {
|
|
|
+ phone: username,
|
|
|
+ password: password,
|
|
|
+ isBinding: isBinding,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ customConfig: {needAuth: false}
|
|
|
}
|
|
|
+ );
|
|
|
+ if (response.status === 201) {
|
|
|
+ const token = response.data.accessToken;
|
|
|
+ await SecureStore.setItemAsync('accessToken', token);
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -250,11 +234,14 @@ class AuthenticationService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async changePassword(confirmedNewPassword: string, data: string) {
|
|
|
+ async changePassword(confirmedNewPassword: string, token: string | null) {
|
|
|
try {
|
|
|
const res = await apiClient.instance.put(
|
|
|
`/clients/customer/pw/forget`,
|
|
|
{ newPassword: confirmedNewPassword },
|
|
|
+ {
|
|
|
+ customConfig: { token }
|
|
|
+ }
|
|
|
);
|
|
|
return true;
|
|
|
} catch (error) {
|
|
|
@@ -271,6 +258,10 @@ class AuthenticationService {
|
|
|
const res = await apiClient.instance.put(
|
|
|
`/clients/customer`,
|
|
|
{ email: email },
|
|
|
+ {
|
|
|
+
|
|
|
+ customConfig: { token }
|
|
|
+ }
|
|
|
);
|
|
|
console.log('Change Name Successfully!');
|
|
|
return true;
|
|
|
@@ -289,6 +280,9 @@ class AuthenticationService {
|
|
|
const res = await apiClient.instance.put(
|
|
|
`/clients/customer`,
|
|
|
{ nickname: name },
|
|
|
+ {
|
|
|
+ customConfig: { token }
|
|
|
+ }
|
|
|
);
|
|
|
console.log('Change Name Successfully!');
|
|
|
return true;
|
|
|
@@ -330,6 +324,9 @@ class AuthenticationService {
|
|
|
const res = await apiClient.instance.put(
|
|
|
`/clients/customer`,
|
|
|
{ phone: convertPhoneStringToNumber },
|
|
|
+ {
|
|
|
+ customConfig: { token }
|
|
|
+ }
|
|
|
);
|
|
|
return true;
|
|
|
} catch (error) {
|
|
|
@@ -347,6 +344,9 @@ class AuthenticationService {
|
|
|
const res = await apiClient.instance.put(
|
|
|
`/clients/customer`,
|
|
|
{ gender: gender },
|
|
|
+ {
|
|
|
+ customConfig: { token }
|
|
|
+ }
|
|
|
);
|
|
|
console.log('Change gender Successfully!');
|
|
|
return true;
|