質問編集履歴
3
言い回しの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,9 +62,9 @@
|
|
62
62
|
|
63
63
|
###追記
|
64
64
|
|
65
|
+
実行例①
|
66
|
+
|
65
67
|
```JavaScript
|
66
|
-
|
67
|
-
//実行例①
|
68
68
|
|
69
69
|
const createAnonymUser = (req, res, next) => {
|
70
70
|
|
@@ -94,9 +94,9 @@
|
|
94
94
|
|
95
95
|
|
96
96
|
|
97
|
+
実行例②
|
98
|
+
|
97
99
|
```JavaScript
|
98
|
-
|
99
|
-
//実行例②
|
100
100
|
|
101
101
|
const createAnonymUser = (req, res, next) => {
|
102
102
|
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -64,6 +64,8 @@
|
|
64
64
|
|
65
65
|
```JavaScript
|
66
66
|
|
67
|
+
//実行例①
|
68
|
+
|
67
69
|
const createAnonymUser = (req, res, next) => {
|
68
70
|
|
69
71
|
console.log('createAnonymUser');
|
@@ -86,11 +88,15 @@
|
|
86
88
|
|
87
89
|
```
|
88
90
|
|
91
|
+
結果①
|
92
|
+
|
89
93
|
![イメージ説明](ef5e7e0840ff06b87d5adab5e37ab6c4.png)
|
90
94
|
|
91
95
|
|
92
96
|
|
93
97
|
```JavaScript
|
98
|
+
|
99
|
+
//実行例②
|
94
100
|
|
95
101
|
const createAnonymUser = (req, res, next) => {
|
96
102
|
|
@@ -122,4 +128,6 @@
|
|
122
128
|
|
123
129
|
```
|
124
130
|
|
131
|
+
結果②
|
132
|
+
|
125
133
|
![イメージ説明](4db23c8e039255c6bea200680fa5ab9c.png)
|
1
コードの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -57,3 +57,69 @@
|
|
57
57
|
app.use('/users', usersRouter);
|
58
58
|
|
59
59
|
```
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
###追記
|
64
|
+
|
65
|
+
```JavaScript
|
66
|
+
|
67
|
+
const createAnonymUser = (req, res, next) => {
|
68
|
+
|
69
|
+
console.log('createAnonymUser');
|
70
|
+
|
71
|
+
if (!req.cookies.anonymUser && !req.user) {
|
72
|
+
|
73
|
+
const anonymUser = (async () => await User.create({ username: 'anonymous', displayName: '名無しさん' }))();
|
74
|
+
|
75
|
+
console.log(anonymUser);
|
76
|
+
|
77
|
+
res.cookie('anonymUser', anonymUser);
|
78
|
+
|
79
|
+
return next();
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
next();
|
84
|
+
|
85
|
+
};
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
![イメージ説明](ef5e7e0840ff06b87d5adab5e37ab6c4.png)
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
```JavaScript
|
94
|
+
|
95
|
+
const createAnonymUser = (req, res, next) => {
|
96
|
+
|
97
|
+
console.log('createAnonymUser');
|
98
|
+
|
99
|
+
if (!req.cookies.anonymUser && !req.user) {
|
100
|
+
|
101
|
+
(async () => {
|
102
|
+
|
103
|
+
const anonymUser = new User({ username: 'anonymous', displayName: '名無しさん' });
|
104
|
+
|
105
|
+
await anonymUser.save();
|
106
|
+
|
107
|
+
res.cookie('anonymUser', anonymUser);
|
108
|
+
|
109
|
+
console.log(anonymUser);
|
110
|
+
|
111
|
+
return next();
|
112
|
+
|
113
|
+
})();
|
114
|
+
|
115
|
+
} else {
|
116
|
+
|
117
|
+
next();
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
};
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
![イメージ説明](4db23c8e039255c6bea200680fa5ab9c.png)
|