@restorecommerce/facade 0.2.1 → 0.2.2
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/CHANGELOG.md
CHANGED
@@ -3,6 +3,17 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [0.2.2](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.2.1...@restorecommerce/facade@0.2.2) (2022-02-15)
|
7
|
+
|
8
|
+
|
9
|
+
### Bug Fixes
|
10
|
+
|
11
|
+
* store facade token in cookies ([5fe1b53](https://github.com/restorecommerce/libs/commit/5fe1b538955993f6d20626968699867f0120589c))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
6
17
|
## [0.2.1](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.2.0...@restorecommerce/facade@0.2.1) (2022-02-14)
|
7
18
|
|
8
19
|
|
package/debug-run.ts
CHANGED
@@ -17,10 +17,35 @@ const createOAuth = () => {
|
|
17
17
|
ctx.body = await exports.login((await ctx.identitySrvClient.oauth.GenerateLinks({})).links);
|
18
18
|
return next();
|
19
19
|
});
|
20
|
+
router.get('/oauth2-logout', async (ctx, next) => {
|
21
|
+
ctx.cookies.set('token', undefined);
|
22
|
+
ctx.status = 303;
|
23
|
+
ctx.redirect('/oauth2-login');
|
24
|
+
ctx.body = 'Redirecting to login page';
|
25
|
+
return next();
|
26
|
+
});
|
20
27
|
router.get('/oauth2-urls', async (ctx, next) => {
|
21
28
|
ctx.body = (await ctx.identitySrvClient.oauth.GenerateLinks({})).links;
|
22
29
|
return next();
|
23
30
|
});
|
31
|
+
router.get('/oauth2-account', async (ctx, next) => {
|
32
|
+
const token = ctx.cookies.get('token');
|
33
|
+
if (!token) {
|
34
|
+
ctx.body = 'user not logged in';
|
35
|
+
return next();
|
36
|
+
}
|
37
|
+
const ids = ctx.identitySrvClient;
|
38
|
+
const user = await ids.user.FindByToken({
|
39
|
+
token: token
|
40
|
+
});
|
41
|
+
if (!user || !user.payload) {
|
42
|
+
ctx.body = 'user not logged in';
|
43
|
+
return next();
|
44
|
+
}
|
45
|
+
ctx.type = 'html';
|
46
|
+
ctx.body = await exports.account(user.payload);
|
47
|
+
return next();
|
48
|
+
});
|
24
49
|
router.post('/oauth2-register', async (ctx, next) => {
|
25
50
|
const ids = ctx.identitySrvClient;
|
26
51
|
const body = ctx.request.body;
|
@@ -34,8 +59,11 @@ const createOAuth = () => {
|
|
34
59
|
guest: false,
|
35
60
|
}));
|
36
61
|
if (user.payload) {
|
37
|
-
|
38
|
-
ctx.
|
62
|
+
const token = await upsertUserToken(ids, user.payload.id);
|
63
|
+
ctx.cookies.set('token', token);
|
64
|
+
ctx.status = 303;
|
65
|
+
ctx.redirect('/oauth2-account');
|
66
|
+
ctx.body = 'Redirecting to account page';
|
39
67
|
return next();
|
40
68
|
}
|
41
69
|
if (user.status) {
|
@@ -50,7 +78,6 @@ const createOAuth = () => {
|
|
50
78
|
code: ctx.request.query['code'],
|
51
79
|
state: ctx.request.query['state']
|
52
80
|
});
|
53
|
-
console.log(user);
|
54
81
|
if (!user.user || !user.user.payload || (user.user.status && user.user.status.code !== 200)) {
|
55
82
|
if (user.email) {
|
56
83
|
ctx.type = 'html';
|
@@ -62,26 +89,32 @@ const createOAuth = () => {
|
|
62
89
|
return next();
|
63
90
|
}
|
64
91
|
}
|
65
|
-
const token =
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
type: 'access_token',
|
71
|
-
expiresIn: expiresIn,
|
72
|
-
payload: utils_1.marshallProtobufAny({
|
73
|
-
accountId: user.user.payload.id,
|
74
|
-
exp: expiresIn,
|
75
|
-
jti: token
|
76
|
-
})
|
77
|
-
});
|
78
|
-
ctx.type = 'html';
|
79
|
-
ctx.body = await exports.account(user.user.payload);
|
92
|
+
const token = await upsertUserToken(ids, user.user.payload.id);
|
93
|
+
ctx.cookies.set('token', token);
|
94
|
+
ctx.status = 303;
|
95
|
+
ctx.redirect('/oauth2-account');
|
96
|
+
ctx.body = 'Redirecting to account page';
|
80
97
|
return next();
|
81
98
|
});
|
82
99
|
return router;
|
83
100
|
};
|
84
101
|
exports.createOAuth = createOAuth;
|
102
|
+
const upsertUserToken = async (ids, accountId) => {
|
103
|
+
const token = utils_1.nanoid();
|
104
|
+
// 1 Month
|
105
|
+
const expiresIn = Date.now() + (1000 * 60 * 60 * 24 * 30);
|
106
|
+
await ids.token.upsert({
|
107
|
+
id: uuid.v4().replace(/-/g, ''),
|
108
|
+
type: 'access_token',
|
109
|
+
expiresIn: expiresIn,
|
110
|
+
payload: utils_1.marshallProtobufAny({
|
111
|
+
accountId: accountId,
|
112
|
+
exp: expiresIn,
|
113
|
+
jti: token
|
114
|
+
})
|
115
|
+
});
|
116
|
+
return token;
|
117
|
+
};
|
85
118
|
let layoutHbs;
|
86
119
|
const layout = async (context) => {
|
87
120
|
if (!layoutHbs) {
|
@@ -16,8 +16,12 @@
|
|
16
16
|
<div class="rc-login flex col justify-center">
|
17
17
|
<div class="self-center justify-center rc-account scale110p">
|
18
18
|
<h2>{{title}}</h2>
|
19
|
-
<div class="
|
19
|
+
<div class="col center justify-center">
|
20
20
|
<h3>Welcome {{user.firstName}} {{user.lastName}}!</h3>
|
21
|
+
|
22
|
+
<a href="/oauth2-logout" class="button emphasized">
|
23
|
+
<div class="icogram"><span class="text">Logout</span></div>
|
24
|
+
</a>
|
21
25
|
</div>
|
22
26
|
</div>
|
23
27
|
</div>
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@restorecommerce/facade",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.2",
|
4
4
|
"description": "Facade for Restorecommerce microservices",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"typings": "dist/index.d.ts",
|
@@ -106,5 +106,5 @@
|
|
106
106
|
"publishConfig": {
|
107
107
|
"access": "public"
|
108
108
|
},
|
109
|
-
"gitHead": "
|
109
|
+
"gitHead": "a3e82fe9170e6bd988d722af28d212e0ec87d8b4"
|
110
110
|
}
|