@blinkdotnew/sdk 0.18.2 → 0.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -240,6 +240,9 @@ await blink.auth.sendMagicLink(email)
240
240
 
241
241
  // Password management
242
242
  await blink.auth.sendPasswordResetEmail(email)
243
+ await blink.auth.sendPasswordResetEmail(email, {
244
+ redirectUrl: 'https://myapp.com/reset-password'
245
+ })
243
246
  await blink.auth.changePassword(oldPass, newPass)
244
247
 
245
248
  // Email verification
@@ -434,6 +437,10 @@ blink.auth.setToken(jwt, persist?)
434
437
  const isAuth = blink.auth.isAuthenticated()
435
438
 
436
439
  // Password management
440
+ await blink.auth.sendPasswordResetEmail('user@example.com')
441
+ await blink.auth.sendPasswordResetEmail('user@example.com', {
442
+ redirectUrl: 'https://myapp.com/reset-password' // Custom reset page
443
+ })
437
444
  await blink.auth.changePassword('oldPass', 'newPass')
438
445
  await blink.auth.confirmPasswordReset(token, newPassword)
439
446
 
@@ -1841,13 +1848,24 @@ const blink = createClient({
1841
1848
  })
1842
1849
 
1843
1850
  function AuthForm() {
1851
+ const [mode, setMode] = useState('signin') // 'signin' | 'signup' | 'reset'
1844
1852
  const [email, setEmail] = useState('')
1845
1853
  const [password, setPassword] = useState('')
1854
+ const [message, setMessage] = useState('')
1846
1855
 
1847
1856
  const handleEmailAuth = async () => {
1848
1857
  try {
1849
- await blink.auth.signInWithEmail(email, password)
1850
- // User state updates via onAuthStateChanged
1858
+ if (mode === 'signin') {
1859
+ await blink.auth.signInWithEmail(email, password)
1860
+ } else if (mode === 'signup') {
1861
+ await blink.auth.signUp({ email, password })
1862
+ setMessage('Account created! Check your email to verify.')
1863
+ } else if (mode === 'reset') {
1864
+ await blink.auth.sendPasswordResetEmail(email, {
1865
+ redirectUrl: 'https://myapp.com/reset-password' // Your custom reset page
1866
+ })
1867
+ setMessage('Password reset email sent! Check your inbox.')
1868
+ }
1851
1869
  } catch (error) {
1852
1870
  console.error('Auth failed:', error.message)
1853
1871
  }
@@ -1862,23 +1880,100 @@ function AuthForm() {
1862
1880
  }
1863
1881
 
1864
1882
  return (
1865
- <form onSubmit={handleEmailAuth}>
1866
- <input
1867
- type="email"
1868
- value={email}
1869
- onChange={(e) => setEmail(e.target.value)}
1870
- placeholder="Email"
1871
- />
1872
- <input
1873
- type="password"
1874
- value={password}
1875
- onChange={(e) => setPassword(e.target.value)}
1876
- placeholder="Password"
1883
+ <div>
1884
+ {message && <p style={{ color: 'green' }}>{message}</p>}
1885
+
1886
+ <form onSubmit={handleEmailAuth}>
1887
+ <input
1888
+ type="email"
1889
+ value={email}
1890
+ onChange={(e) => setEmail(e.target.value)}
1891
+ placeholder="Email"
1892
+ />
1893
+
1894
+ {mode !== 'reset' && (
1895
+ <input
1896
+ type="password"
1897
+ value={password}
1898
+ onChange={(e) => setPassword(e.target.value)}
1899
+ placeholder="Password"
1900
+ />
1901
+ )}
1902
+
1903
+ <button type="submit">
1904
+ {mode === 'signin' ? 'Sign In' : mode === 'signup' ? 'Sign Up' : 'Send Reset Email'}
1905
+ </button>
1906
+ </form>
1907
+
1908
+ {mode !== 'reset' && (
1909
+ <button type="button" onClick={handleSocialAuth}>
1910
+ Continue with Google
1911
+ </button>
1912
+ )}
1913
+
1914
+ <div>
1915
+ {mode === 'signin' && (
1916
+ <>
1917
+ <button onClick={() => setMode('signup')}>Create Account</button>
1918
+ <button onClick={() => setMode('reset')}>Forgot Password?</button>
1919
+ </>
1920
+ )}
1921
+ {mode === 'signup' && (
1922
+ <button onClick={() => setMode('signin')}>Back to Sign In</button>
1923
+ )}
1924
+ {mode === 'reset' && (
1925
+ <button onClick={() => setMode('signin')}>Back to Sign In</button>
1926
+ )}
1927
+ </div>
1928
+ </div>
1929
+ )
1930
+ }
1931
+ ```
1932
+
1933
+ #### 🔄 Custom Reset Page Handling
1934
+
1935
+ **When users click the reset link, handle it in your app:**
1936
+
1937
+ ```typescript
1938
+ // /reset-password page component
1939
+ function ResetPasswordPage() {
1940
+ const [token, setToken] = useState('')
1941
+ const [projectId, setProjectId] = useState('')
1942
+ const [newPassword, setNewPassword] = useState('')
1943
+ const [message, setMessage] = useState('')
1944
+
1945
+ useEffect(() => {
1946
+ // Extract token and projectId from URL params
1947
+ const params = new URLSearchParams(window.location.search)
1948
+ setToken(params.get('token') || '')
1949
+ setProjectId(params.get('projectId') || '')
1950
+ }, [])
1951
+
1952
+ const handleReset = async (e) => {
1953
+ e.preventDefault()
1954
+
1955
+ try {
1956
+ await blink.auth.confirmPasswordReset(token, newPassword)
1957
+ setMessage('Password reset successfully! You can now sign in.')
1958
+ } catch (error) {
1959
+ console.error('Reset failed:', error.message)
1960
+ }
1961
+ }
1962
+
1963
+ if (!token) return <div>Invalid reset link</div>
1964
+
1965
+ return (
1966
+ <form onSubmit={handleReset}>
1967
+ <h1>Set New Password</h1>
1968
+ <input
1969
+ type="password"
1970
+ value={newPassword}
1971
+ onChange={(e) => setNewPassword(e.target.value)}
1972
+ placeholder="Enter new password"
1973
+ minLength={8}
1877
1974
  />
1878
- <button type="submit">Sign In</button>
1879
- <button type="button" onClick={handleSocialAuth}>
1880
- Continue with Google
1881
- </button>
1975
+ <button type="submit">Reset Password</button>
1976
+ {message && <p style={{ color: 'green' }}>{message}</p>}
1882
1977
  </form>
1883
1978
  )
1884
1979
  }
package/dist/index.d.mts CHANGED
@@ -914,7 +914,9 @@ declare class BlinkAuth {
914
914
  /**
915
915
  * Send password reset email (using Blink default email service)
916
916
  */
917
- sendPasswordResetEmail(email: string): Promise<void>;
917
+ sendPasswordResetEmail(email: string, options?: {
918
+ redirectUrl?: string;
919
+ }): Promise<void>;
918
920
  /**
919
921
  * Confirm password reset with token
920
922
  */
package/dist/index.d.ts CHANGED
@@ -914,7 +914,9 @@ declare class BlinkAuth {
914
914
  /**
915
915
  * Send password reset email (using Blink default email service)
916
916
  */
917
- sendPasswordResetEmail(email: string): Promise<void>;
917
+ sendPasswordResetEmail(email: string, options?: {
918
+ redirectUrl?: string;
919
+ }): Promise<void>;
918
920
  /**
919
921
  * Confirm password reset with token
920
922
  */
package/dist/index.js CHANGED
@@ -1501,7 +1501,7 @@ var BlinkAuth = class {
1501
1501
  /**
1502
1502
  * Send password reset email (using Blink default email service)
1503
1503
  */
1504
- async sendPasswordResetEmail(email) {
1504
+ async sendPasswordResetEmail(email, options) {
1505
1505
  try {
1506
1506
  const response = await fetch(`${this.authUrl}/api/auth/password/reset`, {
1507
1507
  method: "POST",
@@ -1510,7 +1510,8 @@ var BlinkAuth = class {
1510
1510
  },
1511
1511
  body: JSON.stringify({
1512
1512
  email,
1513
- projectId: this.config.projectId
1513
+ projectId: this.config.projectId,
1514
+ redirectUrl: options?.redirectUrl
1514
1515
  })
1515
1516
  });
1516
1517
  if (!response.ok) {
package/dist/index.mjs CHANGED
@@ -1499,7 +1499,7 @@ var BlinkAuth = class {
1499
1499
  /**
1500
1500
  * Send password reset email (using Blink default email service)
1501
1501
  */
1502
- async sendPasswordResetEmail(email) {
1502
+ async sendPasswordResetEmail(email, options) {
1503
1503
  try {
1504
1504
  const response = await fetch(`${this.authUrl}/api/auth/password/reset`, {
1505
1505
  method: "POST",
@@ -1508,7 +1508,8 @@ var BlinkAuth = class {
1508
1508
  },
1509
1509
  body: JSON.stringify({
1510
1510
  email,
1511
- projectId: this.config.projectId
1511
+ projectId: this.config.projectId,
1512
+ redirectUrl: options?.redirectUrl
1512
1513
  })
1513
1514
  });
1514
1515
  if (!response.ok) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkdotnew/sdk",
3
- "version": "0.18.2",
3
+ "version": "0.18.3",
4
4
  "description": "Blink TypeScript SDK for client-side applications - Zero-boilerplate CRUD + auth + AI + analytics + notifications for modern SaaS/AI apps",
5
5
  "keywords": [
6
6
  "blink",