Skip to content

Commit 63cf8e8

Browse files
committed
Updated the readme to show a better example of decoding. I cant be the only one that can get confused on this.
1 parent ed2159a commit 63cf8e8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,20 @@ JWT.encode(.HS256("secret")) { builder in
3939
When decoding a JWT, you must supply one or more algorithms and keys.
4040

4141
```swift
42-
JWT.decode("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.2_8pWJfyPup0YwOXK7g9Dn0cF1E3pdn299t4hSeJy5w", .HS256("secret"))
42+
let result = JWT.decode("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.2_8pWJfyPup0YwOXK7g9Dn0cF1E3pdn299t4hSeJy5w", .HS256("secret"))
43+
44+
switch result {
45+
case .Success(let payload):
46+
print(payload)
47+
case .Failure(let failure):
48+
print("decoding failed \(failure)")
49+
}
4350
```
4451

4552
When the JWT may be signed with one out of many algorithms or keys:
4653

4754
```swift
48-
JWT.decode("eyJh...5w", [.HS256("secret"), .HS256("secret2"), .HS512("secure")])
55+
let result = JWT.decode("eyJh...5w", [.HS256("secret"), .HS256("secret2"), .HS512("secure")])
4956
```
5057

5158
#### Supported claims

0 commit comments

Comments
 (0)