tauri-plugin-plauth 1.0.3

Tauri plugin for authentication (PLAUTH) supporting macOS and iOS platforms with ASWebAuthenticationSession
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# Publishing Guide - Tauri Plugin PLAUTH

## Overview

This document records the complete build and publishing process for the Tauri Plugin PLAUTH project, including both Rust (crates.io) and JavaScript/TypeScript (npm) packages.

## Project Structure

```
tauri-plugin-plauth/
├── src/                    # Rust source code
├── guest-js/              # TypeScript client code
├── ios/                    # iOS Swift implementation
├── macos/                  # macOS Swift implementation
├── examples/               # Example applications
├── permissions/            # Tauri permissions
├── Cargo.toml             # Rust package configuration
├── package.json           # NPM package configuration
├── build.rs               # Rust build script
├── rollup.config.js       # JavaScript bundling
└── tsconfig.json          # TypeScript configuration
```

## Prerequisites

- Rust 1.77.2+
- Tauri 2.7.0+
- Node.js 18+
- Yarn package manager
- Xcode (for macOS development)
- Git repository with proper access

## Pre-Publishing Checklist

### 1. Metadata Updates

#### Cargo.toml

- [x] Update version number
- [x] Set proper authors
- [x] Add comprehensive description
- [x] Include license (MIT)
- [x] Add repository URLs
- [x] Set keywords (max 5 for crates.io)
- [x] Configure categories
- [x] Set rust-version

#### package.json

- [x] Update version number
- [x] Set proper author
- [x] Add comprehensive description
- [x] Include license (MIT)
- [x] Add repository URLs
- [x] Set keywords
- [x] Configure exports and types

#### README.md

- [x] Add badges (crates.io, license)
- [x] Include installation instructions
- [x] Add usage examples
- [x] Document API reference
- [x] List platform support
- [x] Include development setup
- [x] Add contributing guidelines

### 2. File Creation

- [x] Create LICENSE file (MIT)
- [x] Create .npmignore for NPM publishing
- [x] Ensure all source files are properly documented

## Build Process

### 1. Build JavaScript/TypeScript Client

```bash
# Install dependencies
yarn install

# Build client
yarn build
```

**Expected Output:**

```
guest-js/index.ts → ./dist-js/index.js, ./dist-js/index.cjs...
created ./dist-js/index.js, ./dist-js/index.cjs in 1.1s
✨  Done in 3.01s.
```

**Generated Files:**

- `dist-js/index.js` (ESM)
- `dist-js/index.cjs` (CommonJS)
- `dist-js/index.d.ts` (TypeScript definitions)

### 2. Build Rust Plugin

```bash
# Build in development mode
cargo build

# Build in release mode
cargo build --release
```

**Expected Output:**

```
Finished `dev` profile [unoptimized + debuginfo] target(s) in 3m 00s
```

**Note:** May show warnings about unused variables (acceptable for publishing)

### 3. Run Tests

```bash
# Run Rust tests
cargo test

# Expected: 0 tests, all passing
```

### 4. Generate Documentation

```bash
# Generate Rust documentation
cargo doc --no-deps

# Expected: Documentation generated in target/doc/
```

### 5. Build Example Application

```bash
cd examples/tauri-app
cargo tauri build
```

**Expected Output:**

```
✓ built in 1.64s
Finished `release` profile [optimized] in 1m 29s
Bundling PlAuth.app
Bundling PlAuth_0.1.0_x64.dmg
```

## Publishing Process

### 1. Git Preparation

```bash
# Check status
git status

# Add all changes
git add .

# Commit changes
git commit -m "feat: prepare for v1.0.0 release - update metadata, documentation, and examples"

# Create version tag
git tag -a v1.0.0 -m "Release version 1.0.0"

# Push code and tag
git push origin develop
git push origin v1.0.0
```

### 2. Publish to Crates.io

#### First Attempt (with verification)

```bash
cargo package
```

**Common Issues:**

- Build script modifies source directory
- Too many keywords (>5)
- Uncommitted changes

#### Solution: Use --no-verify flag

```bash
cargo package --no-verify
cargo publish --no-verify
```

**Expected Output:**

```
Packaged 30 files, 157.5KiB (41.7KiB compressed)
Uploaded tauri-plugin-plauth v1.0.0 to registry `crates-io`
Published tauri-plugin-plauth v1.0.0 at registry `crates-io`
```

### 3. Publish to NPM

```bash
npm publish
```

**Expected Output:**

```
> tauri-plugin-plauth-api@0.1.0 prepublishOnly
> yarn build
+ tauri-plugin-plauth-api@0.1.0
```

## Post-Publishing Verification

### 1. Crates.io

- [x] Visit: https://crates.io/crates/tauri-plugin-plauth
- [x] Verify version 1.0.0 is published
- [x] Check metadata is correct
- [x] Verify documentation links work

### 2. NPM

- [x] Visit: https://www.npmjs.com/package/tauri-plugin-plauth-api
- [x] Verify version 0.1.0 is published
- [x] Check package contents
- [x] Verify installation works

### 3. Git Repository

- [x] Verify tag v1.0.0 exists
- [x] Check all changes are pushed
- [x] Verify working tree is clean

## Troubleshooting

### Common Issues

#### 1. Build Script Modifies Source

**Error:** `Source directory was modified by build.rs during cargo publish`

**Solution:** Use `--no-verify` flag

```bash
cargo publish --no-verify
```

#### 2. Too Many Keywords

**Error:** `expected at most 5 keywords per crate`

**Solution:** Reduce keywords in Cargo.toml to maximum 5

```toml
keywords = ["tauri", "plugin", "authentication", "auth", "macos"]
```

#### 3. Uncommitted Changes

**Error:** `files in the working directory contain changes that were not yet committed`

**Solution:** Commit all changes before publishing

```bash
git add .
git commit -m "your message"
```

#### 4. Swift Linking Issues

**Warning:** `unused variable: 'app'`

**Solution:** This is acceptable for publishing, but can be fixed by prefixing with underscore

```rust
let _app: &AppHandle<R> = app;
```

## Version Management

### Current Versions

- **Rust Plugin**: 1.0.0
- **NPM Package**: 0.1.0

### Version Bumping Strategy

- **Patch (0.0.x)**: Bug fixes, minor improvements
- **Minor (0.x.0)**: New features, backward compatible
- **Major (x.0.0)**: Breaking changes, major features

### Update Process

1. Update version in `Cargo.toml`
2. Update version in `package.json`
3. Update version in `README.md`
4. Create new git tag
5. Follow publishing process

## Dependencies

### Rust Dependencies

```toml
[dependencies]
tauri = "2.7.0"
serde = { version = "1.0", features = ["derive"] }
thiserror = "2"
tauri-swift-runtime = "0.1.2"

[build-dependencies]
tauri-plugin = { version = "2.3.1", features = ["build"] }
swift-rs = { version = "1.0.7", features = ["build"] }
```

### NPM Dependencies

```json
{
  "dependencies": {
    "@tauri-apps/api": ">=2.0.0-beta.6"
  },
  "devDependencies": {
    "@rollup/plugin-typescript": "^12.0.0",
    "rollup": "^4.9.6",
    "typescript": "^5.3.3",
    "tslib": "^2.6.2"
  }
}
```

## Platform Support

### Current Support

- **macOS**: Full support with Swift integration and ASWebAuthenticationSession
-**iOS**: Full support with ASWebAuthenticationSession and UIKit integration
-**Android**: Not implemented (future)
-**Linux**: Not implemented (future)
-**Windows**: Not implemented (future)

### Future Considerations

- Android support with WebView
- Cross-platform authentication standards
- Enhanced iOS/macOS features

### Platform Configuration

- **iOS**: Maintain `ios/` directory structure with ASWebAuthenticationSession
  - `ios/Sources/PlauthPlugin.swift` - Main iOS implementation
  - `ios/Tests/PluginTests/` - iOS unit tests
  - `ios/Package.swift` - Swift package configuration
- **macOS**: Ensure proper web view integration
- Ensure proper permissions and capabilities for authentication

## Security Considerations

### Authentication Security

- Implement proper URL validation
- Handle callback URL schemes securely
- Validate authentication responses
- Implement proper session management

### Input Validation

- Validate all command inputs
- Sanitize data before processing
- Implement proper access controls

## Maintenance

### Regular Tasks

- Keep dependencies updated
- Monitor for security vulnerabilities
- Test thoroughly after dependency updates
- Stay current with Tauri updates

### Code Quality

- Use clippy for Rust code quality
- Maintain consistent formatting
- Regular code reviews and refactoring
- Comprehensive testing

## Links

### Published Packages

- **Crates.io**: https://crates.io/crates/tauri-plugin-plauth
- **NPM**: https://www.npmjs.com/package/tauri-plugin-plauth-api

### Source Code

- **GitHub**: https://github.com/lecaobaophuc0912/tauri-plugin-plauth
- **Issues**: https://github.com/lecaobaophuc0912/tauri-plugin-plauth/issues

### Documentation

- **API Docs**: https://github.com/lecaobaophuc0912/tauri-plugin-plauth
- **Examples**: `examples/tauri-app/`

---

**Last Updated:** December 2024  
**Version:** 1.0.0  
**Maintainer:** Phuc Le <lecaobaophuc@gmail.com>