-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadapter.js
More file actions
72 lines (63 loc) · 1.3 KB
/
adapter.js
File metadata and controls
72 lines (63 loc) · 1.3 KB
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
const { User } = require("./user");
const NAME = Symbol("name");
const USER = Symbol("user");
/**
* An abstract superclass for authentication adapters.
*/
class AuthAdapter {
/**
* Creates a new AuthAdapter.
*
* @param {string} name - The name of the adapter.
*/
constructor(name) {
this[NAME] = `${name}`;
this[USER] = null;
}
/**
* Gets the adapter's name.
*/
get name() {
return this[NAME];
}
/**
* @private
*/
get missingUser() {
return this[USER] === null;
}
/**
* Gets the current user.
*
* @return {User} The current user (may be anonymous or authenticated).
*/
get user() {
return this[USER] || new User();
}
/**
* Sets the current user.
*
* @param {User} value - The user to set.
*/
set user(value) {
if (!(value instanceof User)) {
throw new TypeError("Value must be an instance of the User class");
}
this[USER] = value;
}
/**
* Gets the initial login challenge.
*
* @return {Challenge} The login challenge.
*/
logIn() {
throw new Error("This method must be implemented in a subclass");
}
/**
* Clears all saved authentication information.
*/
logOut() {
throw new Error("This method must be implemented in a subclass");
}
}
module.exports = { AuthAdapter };