Skip to content
This repository was archived by the owner on May 11, 2022. It is now read-only.

Commit 8d9ce0b

Browse files
author
René Kooi
committed
add guest login detection to plugLogin() based on parameters
1 parent e999c97 commit 8d9ce0b

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ plugLogin(
2323
console.log(result.body)
2424
}
2525
)
26+
27+
// "logging in" as a guest
28+
plugLogin({ authToken: true }, (err, result) => {
29+
if (err) throw err
30+
else console.log(result.token)
31+
})
2632
```
2733

2834
## API
@@ -53,16 +59,22 @@ request('https://plug.dj/_/users/me', { json: true, jar: result.jar },
5359
let socket = require('plug-socket')(result.token)
5460
```
5561

56-
### plugLogin.guest(opts={}, cb)
62+
This method is also available as `plugLogin.user`, with the same
63+
parameters.
64+
65+
### plugLogin(opts={}, cb)
5766

5867
Gets a plug.dj session cookie and, optionally, WebSocket authentication token
5968
as a guest user.
6069

61-
`opts` takes the same options as `plugLogin()`.
70+
`opts` takes the same options as user-style `plugLogin()`.
6271

6372
`cb` is a node-style `(err, result)` callback. `result` is similar to what is
6473
returned by `plugLogin()`, minus the `body` property.
6574

75+
This method is also available as `plugLogin.guest`, with the same
76+
parameters.
77+
6678
### plugLogin.getAuthToken(jar, cb)
6779

6880
You can use the `getAuthToken` method separately, for example if you still have

src/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ function guest(opts, cb = null) {
6767
})
6868
}
6969

70-
login.getAuthToken = getAuthToken
71-
login.guest = guest
72-
73-
export default function login(email, password, opts, cb = null) {
70+
function user(email, password, opts, cb = null) {
7471
if (!cb) {
7572
[ cb, opts ] = [ opts, {} ]
7673
}
@@ -86,5 +83,18 @@ export default function login(email, password, opts, cb = null) {
8683
if (e) cb(e)
8784
else cb(null, { body, token, jar: opts.jar })
8885
})
86+
}
8987

88+
login.getAuthToken = getAuthToken
89+
login.guest = guest
90+
login.user = user
91+
92+
export default function login(email, password, opts, cb = null) {
93+
if (typeof email === 'string') {
94+
return user(email, password, opts, cb)
95+
}
96+
else {
97+
[ opts, cb ] = [ email, password ]
98+
return guest(opts, cb)
99+
}
90100
}

0 commit comments

Comments
 (0)