rn-swiftauth-sdk 1.0.0 → 1.0.1

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,7 +2,7 @@
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
8
  ## ✨ Features
@@ -29,30 +29,18 @@ Ensure your environment meets these requirements:
29
29
 
30
30
  ### Step 1: Install the SDK
31
31
 
32
- Since SwiftAuth SDK is currently distributed as a source package, clone and link it locally:
32
+ Install SwiftAuth SDK from npm:
33
33
 
34
34
  ```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
35
+ npm install rn-swiftauth-sdk
44
36
  ```
45
37
 
46
- ### Step 2: Link to Your Project
47
-
48
- Navigate to your React Native/Expo project and install the SDK:
49
-
38
+ **For Expo projects:**
50
39
  ```bash
51
- cd your-project-folder
52
- npm install ../path/to/Auth-SDK_Stage8/swiftauth-sdk
40
+ npx expo install rn-swiftauth-sdk
53
41
  ```
54
42
 
55
- ### Step 3: Install Required Dependencies
43
+ ### Step 2: Install Required Dependencies
56
44
 
57
45
  SwiftAuth requires these peer dependencies:
58
46
 
@@ -79,35 +67,17 @@ npm install @invertase/react-native-apple-authentication
79
67
  npx expo install @invertase/react-native-apple-authentication
80
68
  ```
81
69
 
82
- ### Step 4: Metro Configuration (Important)
70
+ ### Step 3: Install Native Dependencies (Bare React Native only)
83
71
 
84
- Update your `metro.config.js` to resolve the SDK properly:
72
+ If you're using Bare React Native (not Expo), install iOS CocoaPods:
85
73
 
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;
74
+ ```bash
75
+ cd ios
76
+ pod install
77
+ cd ..
102
78
  ```
103
79
 
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`
80
+ That's it! You're ready to start using SwiftAuth SDK.
111
81
 
112
82
  ---
113
83
 
@@ -167,7 +137,7 @@ apply plugin: 'com.google.gms.google-services'
167
137
 
168
138
  1. In Firebase Console, register an **iOS app**
169
139
  2. Download `GoogleService-Info.plist`
170
- 3. Place it in your project: `ios/YourAppName/GoogleService-Info.plist`
140
+ 3. Place it in your project root for Expo, or `ios/YourAppName/GoogleService-Info.plist` for Bare React Native
171
141
 
172
142
  **For Bare React Native:**
173
143
  - Drag `GoogleService-Info.plist` into your Xcode project
@@ -184,7 +154,7 @@ apply plugin: 'com.google.gms.google-services'
184
154
  }
185
155
  ```
186
156
 
187
- **Install CocoaPods (iOS only):**
157
+ **Install CocoaPods (Bare React Native iOS only):**
188
158
  ```bash
189
159
  cd ios
190
160
  pod install
@@ -221,10 +191,10 @@ cd ..
221
191
  ### 5. Apple Sign-In Configuration (Optional, iOS only)
222
192
 
223
193
  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**
194
+ 2. Enable **Sign in with Apple** capability for your App ID
195
+ 3. For Bare React Native: Add the capability in Xcode: **Signing & Capabilities** > **+ Capability** > **Sign in with Apple**
226
196
 
227
- **Update `app.json`:**
197
+ **Update `app.json` for Expo:**
228
198
  ```json
229
199
  {
230
200
  "expo": {
@@ -245,7 +215,7 @@ cd ..
245
215
  // App.tsx
246
216
  import React from 'react';
247
217
  import { SafeAreaProvider } from 'react-native-safe-area-context';
248
- import { AuthProvider, AuthScreen, useAuth } from 'swiftauth-sdk';
218
+ import { AuthProvider, AuthScreen, useAuth } from 'rn-swiftauth-sdk';
249
219
 
250
220
  // Your Firebase configuration
251
221
  const firebaseConfig = {
@@ -422,7 +392,7 @@ Build your own interface using the `useAuth()` hook:
422
392
  ```tsx
423
393
  import { useState } from 'react';
424
394
  import { View, TextInput, Button, Text } from 'react-native';
425
- import { useAuth } from 'swiftauth-sdk';
395
+ import { useAuth } from 'rn-swiftauth-sdk';
426
396
 
427
397
  export const CustomLoginScreen = () => {
428
398
  const { signInWithEmail, error } = useAuth();
@@ -517,37 +487,143 @@ const config = {
517
487
 
518
488
  ---
519
489
 
520
- ## 🧪 Testing
490
+ ## 🔌 Connecting to a Custom Backend
491
+
492
+ The SwiftAuth SDK handles the complexity of authentication (Google, Apple, Email), but you likely have your own API for user data.
493
+
494
+ The SDK exposes a secure Firebase ID Token (`user.token`) that you can send to your backend to identify the user.
495
+
496
+ ### 1. Frontend: Sending the Token
521
497
 
522
- Run the example app to test the SDK:
498
+ In your React Native app, access the token from the `useAuth` hook and include it in the `Authorization` header of your API requests.
499
+
500
+ ```typescript
501
+ import { useAuth } from 'rn-swiftauth-sdk';
502
+
503
+ const UserProfile = () => {
504
+ const { user } = useAuth();
505
+
506
+ const fetchPrivateData = async () => {
507
+ if (!user?.token) return;
508
+
509
+ try {
510
+ const response = await fetch('https://your-api.com/profile', {
511
+ method: 'GET',
512
+ headers: {
513
+ 'Content-Type': 'application/json',
514
+ // Send the token as a Bearer token
515
+ 'Authorization': `Bearer ${user.token}`
516
+ }
517
+ });
518
+
519
+ const data = await response.json();
520
+ console.log('Secure Data:', data);
521
+ } catch (error) {
522
+ console.error('Request failed:', error);
523
+ }
524
+ };
525
+
526
+ return <Button title="Get Profile" onPress={fetchPrivateData} />;
527
+ };
528
+ ```
529
+
530
+ ### 2. Backend: Verifying the Token
531
+
532
+ Your backend must verify this token to ensure the request is legitimate. You can use the Firebase Admin SDK for this.
533
+
534
+ **Example (Node.js / Express):**
535
+
536
+ ```javascript
537
+ const admin = require('firebase-admin');
538
+ const express = require('express');
539
+ const app = express();
540
+
541
+ // 1. Initialize Firebase Admin with your Service Account
542
+ const serviceAccount = require('./path/to/serviceAccountKey.json');
543
+ admin.initializeApp({
544
+ credential: admin.credential.cert(serviceAccount)
545
+ });
546
+
547
+ // 2. Middleware to Verify Token
548
+ const verifyToken = async (req, res, next) => {
549
+ const authHeader = req.headers.authorization;
550
+
551
+ if (!authHeader || !authHeader.startsWith('Bearer ')) {
552
+ return res.status(401).send('Unauthorized');
553
+ }
554
+
555
+ const idToken = authHeader.split('Bearer ')[1];
556
+
557
+ try {
558
+ // Decodes the token and checks signature
559
+ const decodedToken = await admin.auth().verifyIdToken(idToken);
560
+
561
+ // Attach user info to request (uid, email, etc.)
562
+ req.user = decodedToken;
563
+ next();
564
+ } catch (error) {
565
+ res.status(403).send('Invalid Token');
566
+ }
567
+ };
568
+
569
+ // 3. Protect Routes
570
+ app.get('/profile', verifyToken, (req, res) => {
571
+ // Access user info securely
572
+ res.json({ message: `Hello ${req.user.email}, here is your private data.` });
573
+ });
574
+ ```
575
+
576
+ ### Supported Backends
577
+
578
+ This pattern works with any backend language that has a Firebase Admin SDK, including:
579
+
580
+ - Node.js
581
+ - Python
582
+ - Go
583
+ - Java
584
+ - .NET
585
+
586
+ ---
587
+
588
+ ## 🧪 Example App
589
+
590
+ Check out our example implementation:
523
591
 
524
592
  ```bash
525
- cd swiftauth-example
593
+ # Clone the repository
594
+ git clone https://github.com/allcodez/Auth-SDK_Stage8
595
+
596
+ # Navigate to example app
597
+ cd Auth-SDK_Stage8/swiftauth-example
598
+
599
+ # Install dependencies
526
600
  npm install
601
+
602
+ # Start the app
527
603
  npx expo start
528
604
  ```
529
605
 
530
606
  ---
531
607
 
532
- ## 📖 Full Documentation
608
+ ## 📖 Additional Resources
533
609
 
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)
610
+ - [Installation Guide](https://github.com/allcodez/Auth-SDK_Stage8/blob/main/docs/installation.md)
611
+ - [Getting Started](https://github.com/allcodez/Auth-SDK_Stage8/blob/main/docs/getting-started.md)
612
+ - [API Reference](https://github.com/allcodez/Auth-SDK_Stage8/blob/main/docs/api-reference.md)
613
+ - [Usage Examples](https://github.com/allcodez/Auth-SDK_Stage8/blob/main/docs/usage-examples.md)
614
+ - [Error Codes](https://github.com/allcodez/Auth-SDK_Stage8/blob/main/docs/error-codes.md)
539
615
 
540
616
  ---
541
617
 
542
618
  ## 🤝 Contributing
543
619
 
544
- We welcome contributions! See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
620
+ We welcome contributions! See [CONTRIBUTING.md](https://github.com/allcodez/Auth-SDK_Stage8/blob/main/CONTRIBUTING.md) for guidelines.
545
621
 
546
622
  ---
547
623
 
548
624
  ## 📄 License
549
625
 
550
- MIT License - see [LICENSE](./LICENSE) file for details.
626
+ MIT License - see [LICENSE](https://github.com/allcodez/Auth-SDK_Stage8/blob/main/LICENSE) file for details.
551
627
 
552
628
  ---
553
629
 
@@ -556,6 +632,7 @@ MIT License - see [LICENSE](./LICENSE) file for details.
556
632
  - 📧 Email: support@swiftauth.dev
557
633
  - 🐛 Issues: [GitHub Issues](https://github.com/allcodez/Auth-SDK_Stage8/issues)
558
634
  - 💬 Discussions: [GitHub Discussions](https://github.com/allcodez/Auth-SDK_Stage8/discussions)
635
+ - 📦 NPM Package: [rn-swiftauth-sdk](https://www.npmjs.com/package/rn-swiftauth-sdk)
559
636
 
560
637
  ---
561
638
 
@@ -567,7 +644,7 @@ MIT License - see [LICENSE](./LICENSE) file for details.
567
644
  - [ ] Multi-factor authentication (MFA)
568
645
  - [ ] Biometric authentication
569
646
  - [ ] Session refresh tokens
570
- - [ ] NPM package distribution
647
+ - [x] NPM package distribution
571
648
 
572
649
  ---
573
650
 
@@ -0,0 +1,9 @@
1
+ # 👥 Contributors
2
+
3
+ A huge thank you to the team who built the SwiftAuth SDK!
4
+
5
+ * 🛡️ **[@allcodez](https://github.com/allcodez)**
6
+ * 🎨 **[@Peliah](https://github.com/Peliah)**
7
+ * 🚀 **[@ukemeikot](https://github.com/ukemeikot)**
8
+
9
+ Interested in contributing? Pull requests are welcome!
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "rn-swiftauth-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
7
7
  "dist",
8
- "src"
8
+ "src",
9
+ "CONTRIBUTORS.md"
9
10
  ],
10
11
  "scripts": {
11
12
  "build": "tsc",
@@ -59,4 +60,4 @@
59
60
  "react-native-safe-area-context": "^5.6.2",
60
61
  "typescript": "^5.0.0"
61
62
  }
62
- }
63
+ }