Skip to content

Commit

Permalink
fixing merge issues #1
Browse files Browse the repository at this point in the history
  • Loading branch information
mritsurgeon committed Sep 26, 2024
1 parent 8018a45 commit f5a4f79
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 131 deletions.
81 changes: 1 addition & 80 deletions LoginScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,17 @@ import {
Switch,
Alert,
} from 'react-native';
<<<<<<< HEAD
=======
import axios from 'axios';
import qs from 'qs'; // Import qs for query string formatting
import qs from 'qs';

// Global variable for the base URL
let baseUrl = '';
>>>>>>> 4543cb6 (Added source code and configuration files)

const LoginScreen = ({ navigation }) => {
const [url, setUrl] = useState('');
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [isServiceProvider, setIsServiceProvider] = useState(false);

<<<<<<< HEAD
const handleLogin = () => {
if (username && password) {
if (isServiceProvider) {
Expand All @@ -36,80 +31,6 @@ const LoginScreen = ({ navigation }) => {
} else {
// Navigate to regular Dashboard
navigation.replace('Dashboard');
=======
const formatUrl = (inputUrl) => {
let formattedUrl = inputUrl;
if (!formattedUrl.startsWith('https://')) {
formattedUrl = 'https://' + formattedUrl;
}
if (!formattedUrl.endsWith(':1280/api/v3')) {
if (formattedUrl.endsWith('/')) {
formattedUrl = formattedUrl.slice(0, -1);
}
formattedUrl = formattedUrl.replace(/:1280\/api\/v3$/, '');
formattedUrl = formattedUrl + ':1280/api/v3';
}
return formattedUrl;
};

const loginUser = async () => {
baseUrl = formatUrl(url);
console.log(`Formatted URL: ${baseUrl}`); // Debugging line
console.log(`Username: ${username}`); // Debugging line
console.log(`Password: ${password}`); // Debugging line
const requestBody = qs.stringify({
grant_type: 'password',
username: username,
password: password,
});
console.log('Request body:', requestBody); // Debugging line
try {
const response = await axios.post(`${baseUrl}/token`,
requestBody,
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}
);

console.log('Response:', response); // Debugging line

if (response.status >= 200 && response.status < 300) {
const { access_token, refresh_token, mfa_token, expires_in } = response.data;
// Handle tokens as needed
// Store tokens for future API calls
// Example: AsyncStorage.setItem('accessToken', access_token);
return true;
} else {
throw new Error(`HTTP error! status: ${response.status}`);
}
} catch (error) {
console.error('Login error:', error);
if (error.response) {
console.error('Response data:', error.response.data);
console.error('Response status:', error.response.status);
console.error('Response headers:', error.response.headers);
} else if (error.request) {
console.error('Request data:', error.request);
} else {
console.error('Error message:', error.message);
}
Alert.alert('Login failed', error.message);
return false;
}
};

const handleLogin = async () => {
if (username && password && url) {
const loginSuccess = await loginUser();
if (loginSuccess) {
if (isServiceProvider) {
navigation.replace('ServiceProviderDashboard');
} else {
navigation.replace('Dashboard');
}
>>>>>>> 4543cb6 (Added source code and configuration files)
}
} else {
Alert.alert('Please fill in all fields');
Expand Down
39 changes: 0 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,23 @@
"@react-navigation/elements": "^1.3.31",
"@react-navigation/native": "^6.1.18",
"@react-navigation/stack": "^6.4.1",
<<<<<<< HEAD
"expo": "~51.0.28",
"expo-status-bar": "~1.12.1",
"hermes-engine": "^0.11.0",
=======
"axios": "^1.7.7",
"axios-https-proxy-fix": "^0.17.1",
"expo": "~51.0.28",
"expo-status-bar": "~1.12.1",
"hermes-engine": "^0.11.0",
"https": "^1.0.0",
"qs": "^6.13.0",
>>>>>>> 4543cb6 (Added source code and configuration files)
"react": "18.2.0",
"react-native": "0.74.5",
"react-native-chart-kit": "^6.12.0",
"react-native-charts-wrapper": "^0.6.0",
"react-native-gesture-handler": "~2.16.1",
<<<<<<< HEAD
"react-native-reanimated": "~3.10.1",
"react-native-safe-area-context": "^4.11.0",
"react-native-screens": "^3.34.0",
=======
"react-native-https": "^1.0.0",
"react-native-reanimated": "~3.10.1",
"react-native-safe-area-context": "^4.11.0",
"react-native-screens": "^3.34.0",
"react-native-ssl-pinning": "^1.5.7",
>>>>>>> 4543cb6 (Added source code and configuration files)
"react-native-svg": "^15.7.1",
"react-native-svg-transformer": "^1.5.0",
"react-native-vector-icons": "^10.2.0"
Expand Down

0 comments on commit f5a4f79

Please sign in to comment.