updateUsername
Updates the current user’s username.
Returns: Promise<Account>
Error Handling: Throws error if update fails. Error is logged and re-thrown.
import { updateUsername } from '@/services/profile.service';
await updateUsername('cricket_fan_2026');
updateEmail
Updates the current user’s email address. Requires password verification.
Current password for verification
Returns: Promise<Account>
Error Handling: Throws error if update fails. Error is logged and re-thrown.
import { updateEmail } from '@/services/profile.service';
await updateEmail('[email protected]', 'currentPassword123');
Email updates require password verification for security. Make sure the user is authenticated before calling this function.
updatePassword
Changes the current user’s password. Requires the old password for verification.
Current password for verification
Returns: Promise<void>
Error Handling: Throws error if update fails. Error is logged and re-thrown.
import { updatePassword } from '@/services/profile.service';
await updatePassword({
oldPassword: 'oldPass123',
newPassword: 'newSecurePass456'
});
Password changes are security-sensitive operations. Ensure strong password requirements are enforced on the client side.
deleteCurrentSession
Logs out the current user by deleting their active session.
Parameters: None
Returns: Promise<void>
Error Handling: Throws error if deletion fails. Error is logged and re-thrown.
import { deleteCurrentSession } from '@/services/profile.service';
// Log out current user
await deleteCurrentSession();
deleteAllSessions
Logs out the user from all devices by deleting all active sessions.
Parameters: None
Returns: Promise<void>
Error Handling: Throws error if deletion fails. Error is logged and re-thrown.
import { deleteAllSessions } from '@/services/profile.service';
// Log out from all devices
await deleteAllSessions();
Use this function when a user changes their password or suspects unauthorized access to log out all other devices.
updateFavTeam
Updates the user’s favorite cricket team preference.
Name of the favorite cricket team
Returns: Promise<Preferences>
Error Handling: Throws error if update fails. Error is logged and re-thrown.
import { updateFavTeam } from '@/services/profile.service';
await updateFavTeam('India');
The favorite team is stored in user preferences and can be used for personalized content and notifications.
Usage in components
import {
updateUsername,
updateEmail,
updatePassword,
updateFavTeam,
deleteCurrentSession,
deleteAllSessions
} from '@/services/profile.service';
import { account } from '@/libs/appwrite';
function ProfileSettings() {
const handleUsernameChange = async (newUsername: string) => {
try {
await updateUsername(newUsername);
// Refresh user data
const user = await account.get();
console.log('Username updated:', user.name);
} catch (error) {
console.error('Failed to update username');
}
};
const handleLogout = async () => {
try {
await deleteCurrentSession();
// Navigate to login screen
} catch (error) {
console.error('Failed to log out');
}
};
const handleSecurityAction = async () => {
try {
// Change password and log out all other sessions
await updatePassword({
oldPassword: 'current',
newPassword: 'new'
});
await deleteAllSessions();
} catch (error) {
console.error('Security action failed');
}
};
}