Documentation Index
Fetch the complete documentation index at: https://usegately.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Change Password
For logged-in users to change their password:await gately.changePassword(currentPassword, newPassword)
Parameters
| Parameter | Type | Description |
|---|---|---|
currentPassword | string | User’s current password |
newPassword | string | New password (must meet requirements) |
Example
try {
await gately.changePassword('OldPass123!', 'NewSecurePass456!')
alert('Password changed successfully!')
} catch (error) {
alert('Failed to change password: ' + error.message)
}
React Form
import { useState } from 'react'
import { useGately } from '@gately/sdk'
function ChangePasswordForm() {
const { changePassword } = useGately()
const [formData, setFormData] = useState({
currentPassword: '',
newPassword: '',
confirmPassword: ''
})
const [error, setError] = useState('')
const [success, setSuccess] = useState(false)
const [loading, setLoading] = useState(false)
const handleSubmit = async (e) => {
e.preventDefault()
setError('')
setSuccess(false)
// Validate passwords match
if (formData.newPassword !== formData.confirmPassword) {
setError('New passwords do not match')
return
}
setLoading(true)
try {
await changePassword(formData.currentPassword, formData.newPassword)
setSuccess(true)
setFormData({ currentPassword: '', newPassword: '', confirmPassword: '' })
} catch (err) {
setError(err.message)
} finally {
setLoading(false)
}
}
return (
<form onSubmit={handleSubmit}>
{error && <div className="error">{error}</div>}
{success && <div className="success">Password changed successfully!</div>}
<label>
Current Password
<input
type="password"
value={formData.currentPassword}
onChange={(e) => setFormData({ ...formData, currentPassword: e.target.value })}
required
/>
</label>
<label>
New Password
<input
type="password"
value={formData.newPassword}
onChange={(e) => setFormData({ ...formData, newPassword: e.target.value })}
required
/>
</label>
<label>
Confirm New Password
<input
type="password"
value={formData.confirmPassword}
onChange={(e) => setFormData({ ...formData, confirmPassword: e.target.value })}
required
/>
</label>
<button type="submit" disabled={loading}>
{loading ? 'Changing...' : 'Change Password'}
</button>
</form>
)
}
Password Reset (Forgot Password)
For users who forgot their password:Step 1: Request Reset
await gately.requestPasswordReset(email)
Step 2: Confirm Reset
await gately.confirmPasswordReset(email, resetToken, newPassword)
resetToken comes from the URL in the reset email.
Reset Flow Example
Request Form
function ForgotPasswordForm() {
const { requestPasswordReset } = useGately()
const [email, setEmail] = useState('')
const [sent, setSent] = useState(false)
const [error, setError] = useState('')
const handleSubmit = async (e) => {
e.preventDefault()
try {
await requestPasswordReset(email)
setSent(true)
} catch (err) {
setError(err.message)
}
}
if (sent) {
return (
<div className="success">
<h2>Check your email</h2>
<p>We sent a password reset link to {email}</p>
</div>
)
}
return (
<form onSubmit={handleSubmit}>
{error && <div className="error">{error}</div>}
<h2>Forgot Password</h2>
<p>Enter your email to receive a reset link.</p>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Email address"
required
/>
<button type="submit">Send Reset Link</button>
</form>
)
}
Reset Confirmation Page
function ResetPasswordPage() {
const { confirmPasswordReset } = useGately()
const [searchParams] = useSearchParams()
const [password, setPassword] = useState('')
const [confirmPassword, setConfirmPassword] = useState('')
const [error, setError] = useState('')
const [success, setSuccess] = useState(false)
const email = searchParams.get('email')
const token = searchParams.get('token')
const handleSubmit = async (e) => {
e.preventDefault()
if (password !== confirmPassword) {
setError('Passwords do not match')
return
}
try {
await confirmPasswordReset(email, token, password)
setSuccess(true)
} catch (err) {
setError(err.message)
}
}
if (success) {
return (
<div className="success">
<h2>Password Reset</h2>
<p>Your password has been reset successfully.</p>
<Link to="/login">Log In</Link>
</div>
)
}
return (
<form onSubmit={handleSubmit}>
{error && <div className="error">{error}</div>}
<h2>Set New Password</h2>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="New password"
required
/>
<input
type="password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
placeholder="Confirm password"
required
/>
<button type="submit">Reset Password</button>
</form>
)
}
Password Requirements
New passwords must meet these requirements:- Minimum 8 characters
- At least one uppercase letter (A-Z)
- At least one lowercase letter (a-z)
- At least one number (0-9)
Password Strength Indicator
function PasswordStrength({ password }) {
const getStrength = (pwd) => {
let score = 0
if (pwd.length >= 8) score++
if (pwd.length >= 12) score++
if (/[A-Z]/.test(pwd)) score++
if (/[a-z]/.test(pwd)) score++
if (/\d/.test(pwd)) score++
if (/[^A-Za-z0-9]/.test(pwd)) score++
return score
}
const strength = getStrength(password)
const labels = ['Weak', 'Fair', 'Good', 'Strong', 'Very Strong']
return (
<div className="password-strength">
<div className="bar" data-strength={strength} />
<span>{labels[Math.min(strength, 4)]}</span>
</div>
)
}
Error Handling
try {
await gately.changePassword(current, newPass)
} catch (error) {
switch (error.code) {
case 'INVALID_PASSWORD':
showError('Current password is incorrect')
break
case 'WEAK_PASSWORD':
showError('New password does not meet requirements')
break
case 'SAME_PASSWORD':
showError('New password must be different from current')
break
default:
showError('Failed to change password')
}
}