rn-swiftauth-sdk 1.0.0 โ†’ 1.0.2

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
@@ -2,252 +2,130 @@
2
2
 
3
3
  A production-ready React Native authentication SDK powered by Firebase. Built with TypeScript, offering both pre-built UI components and headless hooks for complete flexibility.
4
4
 
5
- [![npm version](https://img.shields.io/npm/v/swiftauth-sdk.svg)](https://www.npmjs.com/package/swiftauth-sdk)
5
+ [![npm version](https://img.shields.io/npm/v/rn-swiftauth-sdk.svg)](https://www.npmjs.com/package/rn-swiftauth-sdk)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
 
8
- ## โœจ Features
8
+ ## Features
9
9
 
10
- - ๐Ÿ” **Email/Password Authentication** - Built-in validation and error handling
11
- - ๐ŸŽจ **Pre-built UI Components** - Beautiful, customizable auth screens out of the box
12
- - ๐ŸŽฃ **Headless Hooks** - Full control with `useAuth()` for custom implementations
13
- - ๐ŸŽ **Social Login Support** - Google and Apple Sign-In (iOS only for Apple)
14
- - ๐Ÿ’พ **Persistent Sessions** - Configurable session management (local/memory)
15
- - ๐ŸŽฏ **TypeScript First** - Full type safety and IntelliSense support
16
- - โšก **Zero Configuration** - Works with minimal setup
17
- - ๐Ÿ“ฑ **Expo & Bare React Native** - Compatible with both workflows
10
+ - **Email/Password Authentication** - Built-in validation and error handling
11
+ - **Pre-built UI Components** - Beautiful, customizable auth screens out of the box
12
+ - **Headless Hooks** - Full control with `useAuth()` for custom implementations
13
+ - **Social Login Support** - Google and Apple Sign-In (iOS only for Apple)
14
+ - **Persistent Sessions** - Configurable session management (local/memory)
15
+ - **TypeScript First** - Full type safety and IntelliSense support
16
+ - **Zero Configuration** - Works with minimal setup
17
+ - **Expo & Bare React Native** - Compatible with both workflows
18
18
 
19
19
  ---
20
20
 
21
- ## ๐Ÿ“ฆ Installation
21
+ ## Installation
22
22
 
23
23
  ### Prerequisites
24
24
 
25
- Ensure your environment meets these requirements:
26
- - **Node.js**: v18 or higher
27
- - **React Native**: v0.70+
28
- - **Expo**: SDK 49+ (Recommended)
25
+ - Node.js v18 or higher
26
+ - React Native v0.70+
27
+ - Expo SDK 49+ (Recommended)
29
28
 
30
- ### Step 1: Install the SDK
31
-
32
- Since SwiftAuth SDK is currently distributed as a source package, clone and link it locally:
29
+ ### Install the SDK
33
30
 
34
31
  ```bash
35
- # Clone the repository
36
- git clone https://github.com/allcodez/Auth-SDK_Stage8
37
-
38
- # Navigate to SDK folder
39
- cd Auth-SDK_Stage8/swiftauth-sdk
40
-
41
- # Install dependencies and build
42
- npm install
43
- npm run build
32
+ npm install rn-swiftauth-sdk
44
33
  ```
45
34
 
46
- ### Step 2: Link to Your Project
47
-
48
- Navigate to your React Native/Expo project and install the SDK:
49
-
35
+ For Expo projects:
50
36
  ```bash
51
- cd your-project-folder
52
- npm install ../path/to/Auth-SDK_Stage8/swiftauth-sdk
37
+ npx expo install rn-swiftauth-sdk
53
38
  ```
54
39
 
55
- ### Step 3: Install Required Dependencies
56
-
57
- SwiftAuth requires these peer dependencies:
40
+ ### Install Required Dependencies
58
41
 
59
42
  ```bash
60
43
  npm install firebase @react-native-async-storage/async-storage react-native-safe-area-context
61
44
  ```
62
45
 
63
- **For Expo projects:**
46
+ For Expo:
64
47
  ```bash
65
48
  npx expo install firebase @react-native-async-storage/async-storage react-native-safe-area-context
66
49
  ```
67
50
 
68
- **For Google Sign-In (Optional):**
51
+ ### Optional: Social Login Dependencies
52
+
53
+ **Google Sign-In:**
69
54
  ```bash
70
55
  npm install @react-native-google-signin/google-signin
71
- # or for Expo
72
- npx expo install @react-native-google-signin/google-signin
73
56
  ```
74
57
 
75
- **For Apple Sign-In (Optional, iOS only):**
58
+ **Apple Sign-In (iOS only):**
76
59
  ```bash
77
60
  npm install @invertase/react-native-apple-authentication
78
- # or for Expo
79
- npx expo install @invertase/react-native-apple-authentication
80
61
  ```
81
62
 
82
- ### Step 4: Metro Configuration (Important)
63
+ ### Bare React Native Only
83
64
 
84
- Update your `metro.config.js` to resolve the SDK properly:
85
-
86
- ```javascript
87
- const { getDefaultConfig } = require('expo/metro-config');
88
- const path = require('path');
89
-
90
- const projectRoot = __dirname;
91
- const workspaceRoot = path.resolve(projectRoot, '../');
92
-
93
- const config = getDefaultConfig(projectRoot);
94
-
95
- config.watchFolders = [workspaceRoot];
96
- config.resolver.nodeModulesPaths = [
97
- path.resolve(projectRoot, 'node_modules'),
98
- path.resolve(workspaceRoot, 'node_modules'),
99
- ];
100
-
101
- module.exports = config;
65
+ Install iOS CocoaPods:
66
+ ```bash
67
+ cd ios && pod install && cd ..
102
68
  ```
103
69
 
104
- ### โš ๏ธ Troubleshooting "Duplicate React"
105
-
106
- If you encounter an "Invalid Hook Call" error:
107
-
108
- 1. Build the SDK: `npm run build`
109
- 2. Delete SDK's `node_modules`: `rm -rf node_modules` inside `swiftauth-sdk`
110
- 3. Clear cache and restart: `npx expo start -c`
111
-
112
70
  ---
113
71
 
114
- ## ๐Ÿ”ง Firebase Setup
72
+ ## Firebase Setup
115
73
 
116
74
  ### 1. Create Firebase Project
117
75
 
118
- 1. Go to [Firebase Console](https://console.firebase.google.com/)
76
+ 1. Go to [Firebase Console](https://console.firebase.google.com)
119
77
  2. Create a new project or select existing one
120
- 3. Register a **Web App** (click the `</>` icon)
78
+ 3. Register a Web App (click the `</>` icon)
121
79
  4. Copy the `firebaseConfig` object
122
80
 
123
81
  ### 2. Enable Authentication Methods
124
82
 
125
- 1. Go to **Authentication** > **Sign-in method**
83
+ 1. Navigate to **Authentication > Sign-in method**
126
84
  2. Enable **Email/Password**
127
85
  3. (Optional) Enable **Google** and/or **Apple** for social login
128
86
 
129
87
  ### 3. Platform-Specific Configuration
130
88
 
131
- #### Android Setup
132
-
133
- 1. In Firebase Console, register an **Android app**
134
- 2. Download `google-services.json`
135
- 3. Place it in your project: `android/app/google-services.json`
136
-
137
- **Update `android/build.gradle`:**
138
- ```gradle
139
- buildscript {
140
- dependencies {
141
- // Add this line
142
- classpath 'com.google.gms:google-services:4.3.15'
143
- }
144
- }
145
- ```
146
-
147
- **Update `android/app/build.gradle`:**
148
- ```gradle
149
- apply plugin: 'com.android.application'
150
- // Add this line at the bottom
151
- apply plugin: 'com.google.gms.google-services'
152
- ```
153
-
154
- **Update `app.json` for Expo:**
155
- ```json
156
- {
157
- "expo": {
158
- "android": {
159
- "googleServicesFile": "./google-services.json",
160
- "package": "com.yourcompany.yourapp"
161
- }
162
- }
163
- }
164
- ```
165
-
166
- #### iOS Setup
167
-
168
- 1. In Firebase Console, register an **iOS app**
169
- 2. Download `GoogleService-Info.plist`
170
- 3. Place it in your project: `ios/YourAppName/GoogleService-Info.plist`
171
-
172
- **For Bare React Native:**
173
- - Drag `GoogleService-Info.plist` into your Xcode project
174
-
175
- **Update `app.json` for Expo:**
176
- ```json
177
- {
178
- "expo": {
179
- "ios": {
180
- "googleServicesFile": "./GoogleService-Info.plist",
181
- "bundleIdentifier": "com.yourcompany.yourapp"
182
- }
183
- }
184
- }
185
- ```
186
-
187
- **Install CocoaPods (iOS only):**
188
- ```bash
189
- cd ios
190
- pod install
191
- cd ..
192
- ```
193
-
194
- ### 4. Google Sign-In Configuration (Optional)
195
-
196
- #### Get Google Client IDs
197
-
198
- 1. Go to [Google Cloud Console](https://console.cloud.google.com/)
199
- 2. Select your Firebase project
200
- 3. Go to **APIs & Services** > **Credentials**
201
- 4. You'll need:
202
- - **Web Client ID** (for all platforms)
203
- - **iOS Client ID** (optional, iOS-specific)
204
-
205
- **Update `app.json` for Google Sign-In:**
206
- ```json
207
- {
208
- "expo": {
209
- "ios": {
210
- "bundleIdentifier": "com.yourcompany.yourapp",
211
- "googleServicesFile": "./GoogleService-Info.plist"
212
- },
213
- "android": {
214
- "package": "com.yourcompany.yourapp",
215
- "googleServicesFile": "./google-services.json"
89
+ **Android:**
90
+ - Register an Android app in Firebase Console
91
+ - Download `google-services.json` and place in `android/app/`
92
+ - Add to `android/build.gradle`:
93
+ ```gradle
94
+ classpath 'com.google.gms:google-services:4.3.15'
95
+ ```
96
+ - Add to `android/app/build.gradle`:
97
+ ```gradle
98
+ apply plugin: 'com.google.gms.google-services'
99
+ ```
100
+
101
+ **iOS:**
102
+ - Register an iOS app in Firebase Console
103
+ - Download `GoogleService-Info.plist` and place in project root (Expo) or `ios/YourAppName/` (Bare)
104
+ - Update `app.json`:
105
+ ```json
106
+ {
107
+ "expo": {
108
+ "ios": {
109
+ "googleServicesFile": "./GoogleService-Info.plist",
110
+ "bundleIdentifier": "com.yourcompany.yourapp"
111
+ }
216
112
  }
217
113
  }
218
- }
219
- ```
220
-
221
- ### 5. Apple Sign-In Configuration (Optional, iOS only)
114
+ ```
222
115
 
223
- 1. Go to your [Apple Developer Account](https://developer.apple.com/)
224
- 2. Enable **Sign in with Apple** capability
225
- 3. Add the capability in Xcode: **Signing & Capabilities** > **+ Capability** > **Sign in with Apple**
226
-
227
- **Update `app.json`:**
228
- ```json
229
- {
230
- "expo": {
231
- "ios": {
232
- "usesAppleSignIn": true
233
- }
234
- }
235
- }
236
- ```
116
+ For detailed Firebase setup instructions, see the [Firebase documentation](https://firebase.google.com/docs/ios/setup).
237
117
 
238
118
  ---
239
119
 
240
- ## ๐Ÿš€ Quick Start
120
+ ## Quick Start
241
121
 
242
- ### Basic Setup (Email Authentication)
122
+ ### Basic Email Authentication
243
123
 
244
- ```tsx
245
- // App.tsx
124
+ ```typescript
246
125
  import React from 'react';
247
126
  import { SafeAreaProvider } from 'react-native-safe-area-context';
248
- import { AuthProvider, AuthScreen, useAuth } from 'swiftauth-sdk';
127
+ import { AuthProvider, AuthScreen, useAuth } from 'rn-swiftauth-sdk';
249
128
 
250
- // Your Firebase configuration
251
129
  const firebaseConfig = {
252
130
  apiKey: "AIzaSyD-Your-Actual-Key",
253
131
  authDomain: "your-project.firebaseapp.com",
@@ -259,12 +137,7 @@ const firebaseConfig = {
259
137
 
260
138
  const MainNavigation = () => {
261
139
  const { user } = useAuth();
262
-
263
- if (!user) {
264
- return <AuthScreen />;
265
- }
266
-
267
- return <HomeScreen user={user} />;
140
+ return user ? <HomeScreen user={user} /> : <AuthScreen />;
268
141
  };
269
142
 
270
143
  export default function App() {
@@ -280,11 +153,14 @@ export default function App() {
280
153
 
281
154
  ### With Social Login
282
155
 
283
- ```tsx
156
+ ```typescript
284
157
  const firebaseConfig = {
285
158
  apiKey: "AIzaSyD-Your-Actual-Key",
286
159
  authDomain: "your-project.firebaseapp.com",
287
160
  projectId: "your-project-id",
161
+ storageBucket: "your-project.appspot.com",
162
+ messagingSenderId: "123456789",
163
+ appId: "1:123456789:web:abcdef",
288
164
 
289
165
  // Enable social login
290
166
  enableGoogle: true,
@@ -297,44 +173,16 @@ const firebaseConfig = {
297
173
 
298
174
  ---
299
175
 
300
- ## ๐Ÿ“š API Reference
176
+ ## API Reference
301
177
 
302
178
  ### `<AuthProvider>`
303
179
 
304
180
  Wraps your app and provides authentication context.
305
181
 
306
- **Props:**
307
-
308
182
  | Prop | Type | Required | Description |
309
183
  |------|------|----------|-------------|
310
- | `config` | `AuthConfig` | Yes | Firebase configuration object |
311
- | `children` | `ReactNode` | Yes | Your app components |
312
-
313
- **AuthConfig Interface:**
314
-
315
- ```typescript
316
- interface AuthConfig {
317
- // Firebase credentials (Required)
318
- apiKey: string;
319
- authDomain: string;
320
- projectId: string;
321
- storageBucket?: string;
322
- messagingSenderId?: string;
323
- appId?: string;
324
-
325
- // Session persistence
326
- persistence?: 'local' | 'memory'; // Default: 'local'
327
-
328
- // Feature flags
329
- enableEmail?: boolean; // Default: true
330
- enableGoogle?: boolean; // Default: false
331
- enableApple?: boolean; // Default: false (iOS only)
332
-
333
- // Google Sign-In
334
- googleWebClientId?: string;
335
- googleIosClientId?: string;
336
- }
337
- ```
184
+ | config | AuthConfig | Yes | Firebase configuration object |
185
+ | children | ReactNode | Yes | Your app components |
338
186
 
339
187
  ### `useAuth()` Hook
340
188
 
@@ -342,63 +190,33 @@ Access authentication state and methods.
342
190
 
343
191
  ```typescript
344
192
  const {
345
- user, // Current user object or null
346
- status, // 'AUTHENTICATED' | 'UNAUTHENTICATED' | 'LOADING'
347
- error, // Last error object or null
348
- signInWithEmail,
349
- signUpWithEmail,
350
- signOut,
351
- clearError
193
+ user, // Current user object or null
194
+ status, // AuthStatus enum
195
+ error, // Last error object or null
196
+ isLoading, // Boolean loading state
197
+ signInWithEmail, // Sign in method
198
+ signUpWithEmail, // Sign up method
199
+ signOut, // Sign out method
200
+ clearError // Clear error state
352
201
  } = useAuth();
353
202
  ```
354
203
 
355
- **Methods:**
204
+ #### Available Methods
356
205
 
357
206
  | Method | Signature | Description |
358
207
  |--------|-----------|-------------|
359
- | `signInWithEmail` | `(email: string, password: string) => Promise<void>` | Sign in existing user |
360
- | `signUpWithEmail` | `(email: string, password: string) => Promise<void>` | Create new account |
208
+ | `signInWithEmail` | `(options: {email, password}) => Promise<void>` | Sign in existing user |
209
+ | `signUpWithEmail` | `(options: {email, password}) => Promise<void>` | Create new account |
361
210
  | `signOut` | `() => Promise<void>` | Log out current user |
362
211
  | `clearError` | `() => void` | Clear error state |
363
212
 
364
- ### `<AuthScreen>` Component
365
-
366
- Pre-built authentication UI with login and signup.
367
-
368
- **Props:**
369
-
370
- | Prop | Type | Default | Description |
371
- |------|------|---------|-------------|
372
- | `styles` | `AuthScreenStyles` | `undefined` | Custom styles object |
373
- | `titles` | `object` | `undefined` | Custom text labels |
374
- | `showPasswordHints` | `boolean` | `true` | Show password requirements |
375
-
376
- **Example:**
377
-
378
- ```tsx
379
- <AuthScreen
380
- titles={{
381
- loginTitle: "Welcome Back",
382
- loginSubtitle: "Sign in to continue",
383
- signupTitle: "Create Account",
384
- signupSubtitle: "Join us today"
385
- }}
386
- styles={{
387
- container: { backgroundColor: '#f5f5f5' },
388
- button: { backgroundColor: '#007AFF' },
389
- buttonText: { color: '#ffffff' }
390
- }}
391
- showPasswordHints={true}
392
- />
393
- ```
394
-
395
213
  ---
396
214
 
397
- ## ๐ŸŽจ Customization Examples
215
+ ## Customization
398
216
 
399
- ### Dark Mode Theme
217
+ ### Dark Mode Theme Example
400
218
 
401
- ```tsx
219
+ ```typescript
402
220
  <AuthScreen
403
221
  styles={{
404
222
  container: { backgroundColor: '#1a1a1a' },
@@ -415,100 +233,83 @@ Pre-built authentication UI with login and signup.
415
233
  />
416
234
  ```
417
235
 
418
- ### Custom UI (Headless)
419
-
420
- Build your own interface using the `useAuth()` hook:
236
+ ---
421
237
 
422
- ```tsx
423
- import { useState } from 'react';
424
- import { View, TextInput, Button, Text } from 'react-native';
425
- import { useAuth } from 'swiftauth-sdk';
238
+ ## Error Handling
426
239
 
427
- export const CustomLoginScreen = () => {
428
- const { signInWithEmail, error } = useAuth();
429
- const [email, setEmail] = useState('');
430
- const [password, setPassword] = useState('');
240
+ SwiftAuth maps Firebase errors to user-friendly messages:
431
241
 
432
- const handleLogin = async () => {
433
- try {
434
- await signInWithEmail(email, password);
435
- } catch (err) {
436
- console.error('Login failed:', err);
437
- }
438
- };
242
+ | Error Code | User Message |
243
+ |------------|--------------|
244
+ | `auth/invalid-credentials` | "Invalid email or password." |
245
+ | `auth/user-not-found` | "Invalid email or password." |
246
+ | `auth/email-already-in-use` | "This email is already registered." |
247
+ | `auth/weak-password` | "Password is too weak." |
248
+ | `auth/network-request-failed` | "Network error. Please check your connection." |
439
249
 
440
- return (
441
- <View style={{ padding: 20 }}>
442
- <Text style={{ fontSize: 24, marginBottom: 20 }}>Login</Text>
443
-
444
- {error && <Text style={{ color: 'red' }}>{error.message}</Text>}
445
-
446
- <TextInput
447
- placeholder="Email"
448
- value={email}
449
- onChangeText={setEmail}
450
- style={{ borderWidth: 1, padding: 10, marginBottom: 10 }}
451
- />
452
-
453
- <TextInput
454
- placeholder="Password"
455
- value={password}
456
- onChangeText={setPassword}
457
- secureTextEntry
458
- style={{ borderWidth: 1, padding: 10, marginBottom: 20 }}
459
- />
460
-
461
- <Button title="Sign In" onPress={handleLogin} />
462
- </View>
463
- );
464
- };
465
- ```
250
+ ### Basic Usage
466
251
 
467
- ---
252
+ ```typescript
253
+ const { error } = useAuth();
468
254
 
469
- ## โš ๏ธ Error Handling
255
+ if (error) {
256
+ return <Text style={{ color: 'red' }}>{error.message}</Text>;
257
+ }
258
+ ```
470
259
 
471
- SwiftAuth maps Firebase errors to user-friendly codes:
260
+ ### Advanced: Raw Firebase Errors
472
261
 
473
- | Error Code | Meaning | User Message |
474
- |------------|---------|--------------|
475
- | `auth/invalid-credentials` | Wrong email/password | "Invalid email or password." |
476
- | `auth/user-not-found` | Account doesn't exist | "Invalid email or password." |
477
- | `auth/email-already-in-use` | Email already registered | "This email is already registered." |
478
- | `auth/weak-password` | Password too weak | "Password is too weak." |
479
- | `auth/network-request-failed` | No internet connection | "Network error. Please check your connection." |
480
- | `auth/invalid-email` | Invalid email format | "Invalid email address." |
481
- | `auth/configuration-error` | Missing API keys | "Authentication is not configured correctly." |
262
+ For custom UI implementations, access raw Firebase errors:
482
263
 
483
- **Usage:**
264
+ **Method 1: Try/Catch Block**
265
+ ```typescript
266
+ const { signInWithEmail } = useAuth();
267
+
268
+ const handleLogin = async () => {
269
+ try {
270
+ await signInWithEmail({ email, password });
271
+ } catch (rawError: any) {
272
+ if (rawError.code === 'auth/requires-recent-login') {
273
+ showReauthModal();
274
+ } else if (rawError.code === 'auth/quota-exceeded') {
275
+ Alert.alert("System Overload", "Please try again later.");
276
+ }
277
+ }
278
+ };
279
+ ```
484
280
 
485
- ```tsx
281
+ **Method 2: Global State**
282
+ ```typescript
486
283
  const { error } = useAuth();
487
284
 
488
- if (error) {
489
- if (error.code === 'auth/network-request-failed') {
490
- return <OfflineBanner />;
285
+ useEffect(() => {
286
+ if (error?.originalError) {
287
+ const rawCode = (error.originalError as any).code;
288
+ console.log("Raw Firebase Code:", rawCode);
289
+
290
+ if (rawCode === 'auth/invalid-email') {
291
+ setLocalizedMessage(t('errors.bad_email'));
292
+ }
491
293
  }
492
- return <Text style={{ color: 'red' }}>{error.message}</Text>;
493
- }
294
+ }, [error]);
494
295
  ```
495
296
 
496
297
  ---
497
298
 
498
- ## ๐Ÿ” Session Management
299
+ ## Session Management
499
300
 
500
301
  ### Keep User Logged In (Default)
501
302
 
502
- ```tsx
303
+ ```typescript
503
304
  const config = {
504
305
  ...firebaseConfig,
505
306
  persistence: 'local' // User stays logged in
506
307
  };
507
308
  ```
508
309
 
509
- ### Banking App Mode
310
+ ### Memory-Only Session
510
311
 
511
- ```tsx
312
+ ```typescript
512
313
  const config = {
513
314
  ...firebaseConfig,
514
315
  persistence: 'memory' // User logged out when app closes
@@ -517,58 +318,107 @@ const config = {
517
318
 
518
319
  ---
519
320
 
520
- ## ๐Ÿงช Testing
321
+ ## Backend Integration
521
322
 
522
- Run the example app to test the SDK:
323
+ The SDK exposes a secure Firebase ID Token (`user.token`) for backend authentication.
523
324
 
524
- ```bash
525
- cd swiftauth-example
526
- npm install
527
- npx expo start
325
+ ### Frontend: Sending the Token
326
+
327
+ ```typescript
328
+ import { useAuth } from 'rn-swiftauth-sdk';
329
+
330
+ const UserProfile = () => {
331
+ const { user } = useAuth();
332
+
333
+ const fetchPrivateData = async () => {
334
+ if (!user?.token) return;
335
+
336
+ try {
337
+ const response = await fetch('https://your-api.com/profile', {
338
+ method: 'GET',
339
+ headers: {
340
+ 'Content-Type': 'application/json',
341
+ 'Authorization': `Bearer ${user.token}`
342
+ }
343
+ });
344
+
345
+ const data = await response.json();
346
+ console.log(data);
347
+ } catch (error) {
348
+ console.error('Request failed:', error);
349
+ }
350
+ };
351
+
352
+ return <Button title="Get Profile" onPress={fetchPrivateData} />;
353
+ };
528
354
  ```
529
355
 
530
- ---
356
+ ### Backend: Verifying the Token (Node.js)
531
357
 
532
- ## ๐Ÿ“– Full Documentation
358
+ ```javascript
359
+ const admin = require('firebase-admin');
533
360
 
534
- - [Installation Guide](./docs/installation.md)
535
- - [Getting Started](./docs/getting-started.md)
536
- - [API Reference](./docs/api-reference.md)
537
- - [Usage Examples](./docs/usage-examples.md)
538
- - [Error Codes](./docs/error-codes.md)
361
+ // Middleware to verify Firebase ID token
362
+ const verifyToken = async (req, res, next) => {
363
+ const authHeader = req.headers.authorization;
364
+
365
+ if (!authHeader || !authHeader.startsWith('Bearer ')) {
366
+ return res.status(401).send('Unauthorized');
367
+ }
368
+
369
+ const idToken = authHeader.split('Bearer ')[1];
370
+
371
+ try {
372
+ const decodedToken = await admin.auth().verifyIdToken(idToken);
373
+ req.user = decodedToken;
374
+ next();
375
+ } catch (error) {
376
+ res.status(403).send('Invalid Token');
377
+ }
378
+ };
379
+
380
+ // Protected route example
381
+ app.get('/profile', verifyToken, (req, res) => {
382
+ res.json({ userId: req.user.uid, email: req.user.email });
383
+ });
384
+ ```
539
385
 
540
386
  ---
541
387
 
542
- ## ๐Ÿค Contributing
388
+ ## Example App
543
389
 
544
- We welcome contributions! See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
390
+ Check out our example implementation:
545
391
 
546
- ---
392
+ ```bash
393
+ # Clone the repository
394
+ git clone https://github.com/allcodez/Auth-SDK_Stage8
547
395
 
548
- ## ๐Ÿ“„ License
396
+ # Navigate to example app
397
+ cd Auth-SDK_Stage8/swiftauth-example
549
398
 
550
- MIT License - see [LICENSE](./LICENSE) file for details.
399
+ # Install dependencies
400
+ npm install
401
+
402
+ # Start the app
403
+ npx expo start
404
+ ```
551
405
 
552
406
  ---
553
407
 
554
- ## ๐Ÿ†˜ Support
408
+ ## Contributing
555
409
 
556
- - ๐Ÿ“ง Email: support@swiftauth.dev
557
- - ๐Ÿ› Issues: [GitHub Issues](https://github.com/allcodez/Auth-SDK_Stage8/issues)
558
- - ๐Ÿ’ฌ Discussions: [GitHub Discussions](https://github.com/allcodez/Auth-SDK_Stage8/discussions)
410
+ We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
559
411
 
560
412
  ---
561
413
 
562
- ## ๐ŸŽฏ Roadmap
414
+ ## License
563
415
 
564
- - [ ] Password reset functionality
565
- - [ ] Email verification
566
- - [ ] Phone authentication
567
- - [ ] Multi-factor authentication (MFA)
568
- - [ ] Biometric authentication
569
- - [ ] Session refresh tokens
570
- - [ ] NPM package distribution
416
+ MIT License - see [LICENSE](LICENSE) file for details.
571
417
 
572
418
  ---
573
419
 
574
- Made with โค๏ธ by the SwiftAuth Team
420
+ ## Support
421
+
422
+ - **Issues:** [GitHub Issues](https://github.com/allcodez/Auth-SDK_Stage8/issues)
423
+ - **NPM Package:** [rn-swiftauth-sdk](https://www.npmjs.com/package/rn-swiftauth-sdk)
424
+ - **Documentation:** [Full Docs](https://github.com/allcodez/Auth-SDK_Stage8)