mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 09:45:20 +00:00
- Implemented connecting multiple accounts for apple
This commit is contained in:
@ -284,8 +284,11 @@ const CalendarSettingsPage = (props: {
|
||||
newUserData.microsoftAccounts = microsoftAccounts;
|
||||
}
|
||||
} else if (provider === "apple") {
|
||||
newUserData.appleToken = null;
|
||||
newUserData.appleMail = null;
|
||||
let appleAccounts = profileData?.appleAccounts;
|
||||
if (appleAccounts) {
|
||||
appleAccounts[email] = null;
|
||||
newUserData.appleAccounts = appleAccounts;
|
||||
}
|
||||
}
|
||||
await updateUserData({newUserData});
|
||||
};
|
||||
@ -311,6 +314,16 @@ const CalendarSettingsPage = (props: {
|
||||
});
|
||||
}
|
||||
|
||||
let isConnectedToApple = false;
|
||||
if (profileData?.appleAccounts) {
|
||||
Object.values(profileData?.appleAccounts).forEach((item) => {
|
||||
if (item !== null) {
|
||||
isConnectedToApple = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollView>
|
||||
<View marginH-30 marginB-30>
|
||||
@ -448,8 +461,8 @@ const CalendarSettingsPage = (props: {
|
||||
}) : null}
|
||||
|
||||
<Button
|
||||
onPress={() => !profileData?.appleToken ? handleAppleSignIn() : clearToken("apple")}
|
||||
label={profileData?.appleToken ? `Disconnect ${profileData.appleMail}` : "Connect Apple"}
|
||||
onPress={() => handleAppleSignIn()}
|
||||
label={"Connect Apple"}
|
||||
labelStyle={styles.addCalLbl}
|
||||
labelProps={{
|
||||
numberOfLines: 2
|
||||
@ -463,6 +476,26 @@ const CalendarSettingsPage = (props: {
|
||||
color="black"
|
||||
text70BL
|
||||
/>
|
||||
{profileData?.appleAccounts ? Object.keys(profileData?.appleAccounts)?.map((appleEmail) => {
|
||||
const appleToken = profileData?.appleAccounts?.[appleEmail];
|
||||
return appleToken && <Button
|
||||
key={appleEmail}
|
||||
onPress={() => clearToken("apple", appleEmail)}
|
||||
label={`Disconnect ${appleEmail}`}
|
||||
labelStyle={styles.addCalLbl}
|
||||
labelProps={{
|
||||
numberOfLines: 2
|
||||
}}
|
||||
iconSource={() => (
|
||||
<View marginR-15>
|
||||
<AppleIcon/>
|
||||
</View>
|
||||
)}
|
||||
style={styles.addCalBtn}
|
||||
color="black"
|
||||
text70BL
|
||||
/>
|
||||
}) : null}
|
||||
|
||||
<Button
|
||||
onPress={() => handleMicrosoftSignIn()}
|
||||
@ -483,6 +516,7 @@ const CalendarSettingsPage = (props: {
|
||||
{profileData?.microsoftAccounts ? Object.keys(profileData?.microsoftAccounts)?.map((microsoftEmail) => {
|
||||
const microsoftToken = profileData?.microsoftAccounts?.[microsoftEmail];
|
||||
return microsoftToken && <Button
|
||||
key={microsoftEmail}
|
||||
onPress={() => clearToken("outlook", microsoftEmail)}
|
||||
label={`Disconnect ${microsoftEmail}`}
|
||||
labelStyle={styles.addCalLbl}
|
||||
@ -500,7 +534,7 @@ const CalendarSettingsPage = (props: {
|
||||
/>
|
||||
}) : null}
|
||||
|
||||
{(isConnectedToGoogle || isConnectedToMicrosoft || profileData?.appleMail) && (
|
||||
{(isConnectedToGoogle || isConnectedToMicrosoft || isConnectedToApple) && (
|
||||
<>
|
||||
<Text style={styles.subTitle} marginT-30 marginB-20>
|
||||
Connected Calendars
|
||||
@ -508,7 +542,7 @@ const CalendarSettingsPage = (props: {
|
||||
|
||||
<View style={styles.noPaddingCard}>
|
||||
<View style={{marginTop: 20}}>
|
||||
{Object.keys(profileData?.googleAccounts)?.map((googleEmail) => {
|
||||
{profileData?.googleAccounts && Object.keys(profileData?.googleAccounts)?.map((googleEmail) => {
|
||||
const googleToken = profileData?.googleAccounts?.[googleEmail];
|
||||
return googleToken && (
|
||||
<TouchableOpacity
|
||||
@ -541,21 +575,22 @@ const CalendarSettingsPage = (props: {
|
||||
)
|
||||
})}
|
||||
|
||||
|
||||
{!!profileData?.appleMail && (
|
||||
{profileData?.appleAccounts && Object.keys(profileData?.appleAccounts)?.map((appleEmail) => {
|
||||
const appleToken = profileData?.appleAccounts?.[appleEmail];
|
||||
return appleToken && (
|
||||
<TouchableOpacity
|
||||
onPress={() => fetchAndSaveAppleEvents({
|
||||
email: profileData?.appleMail!,
|
||||
token: profileData?.appleToken!
|
||||
email: appleEmail,
|
||||
token: appleToken
|
||||
})}>
|
||||
<View row paddingR-20 center>
|
||||
<Button
|
||||
disabled={isSyncingApple}
|
||||
onPress={() => fetchAndSaveAppleEvents({
|
||||
email: profileData?.appleMail!,
|
||||
token: profileData?.appleToken!
|
||||
email: appleEmail,
|
||||
token: appleToken
|
||||
})}
|
||||
label={`Sync ${profileData?.appleMail}`}
|
||||
label={`Sync ${appleEmail}`}
|
||||
labelStyle={styles.addCalLbl}
|
||||
labelProps={{numberOfLines: 3}}
|
||||
iconSource={() => (
|
||||
@ -574,9 +609,10 @@ const CalendarSettingsPage = (props: {
|
||||
)}
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
)
|
||||
})}
|
||||
|
||||
{Object.keys(profileData?.microsoftAccounts)?.map((microsoftEmail) => {
|
||||
{profileData?.microsoftAccounts && Object.keys(profileData?.microsoftAccounts)?.map((microsoftEmail) => {
|
||||
const microsoftToken = profileData?.microsoftAccounts?.[microsoftEmail];
|
||||
return microsoftToken && (
|
||||
<TouchableOpacity
|
||||
|
@ -220,11 +220,15 @@ exports.refreshTokens = functions.pubsub.schedule('every 12 hours').onRun(async
|
||||
}
|
||||
}
|
||||
|
||||
if (profileData.appleToken) {
|
||||
if (profileData.appleAccounts) {
|
||||
try {
|
||||
const refreshedAppleToken = await refreshAppleToken(profileData.appleToken);
|
||||
await profileDoc.ref.update({appleToken: refreshedAppleToken});
|
||||
for (const appleEmail of Object.keys(profileData?.appleAccounts)) {
|
||||
const appleToken = profileData?.appleAccounts?.[appleEmail];
|
||||
const refreshedAppleToken = await refreshAppleToken(appleToken);
|
||||
const updatedAppleAccounts = {...profileData.appleAccounts, [appleEmail]: refreshedAppleToken};
|
||||
await profileDoc.ref.update({appleAccunts: updatedAppleAccounts});
|
||||
console.log(`Apple token updated for user ${profileDoc.id}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error refreshing Apple token for user ${profileDoc.id}:`, error.message);
|
||||
}
|
||||
|
@ -18,15 +18,12 @@ export interface UserProfile {
|
||||
familyId?: string;
|
||||
uid?: string;
|
||||
pfp?: string;
|
||||
microsoftToken?: string | null;
|
||||
appleToken?: string | null;
|
||||
eventColor?: string | null;
|
||||
outlookMail?: string | null;
|
||||
appleMail?: string | null;
|
||||
timeZone?: string | null;
|
||||
firstDayOfWeek?: string | null;
|
||||
googleAccounts?: Object;
|
||||
microsoftAccounts?: Object;
|
||||
appleAccounts?: Object;
|
||||
}
|
||||
|
||||
export interface ParentProfile extends UserProfile {
|
||||
|
Reference in New Issue
Block a user