add cookie
This commit is contained in:
@@ -7,7 +7,6 @@ app
|
||||
path: 'user',
|
||||
key: 'me',
|
||||
middleware: ['auth'],
|
||||
isDebug: true,
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state?.tokenUser || {};
|
||||
@@ -39,9 +38,12 @@ app
|
||||
if (!user && email) {
|
||||
user = await User.findOne({ where: { email } });
|
||||
}
|
||||
console.log('user logiin', ctx.query)
|
||||
console.log('user logiin', user)
|
||||
console.log('users', (await User.findAll()).map(u => u.username))
|
||||
console.log('user logiin', ctx.query);
|
||||
console.log('user logiin', user);
|
||||
console.log(
|
||||
'users',
|
||||
(await User.findAll()).map((u) => u.username),
|
||||
);
|
||||
if (!user) {
|
||||
ctx.throw(500, 'Login Failed');
|
||||
}
|
||||
@@ -49,10 +51,30 @@ app
|
||||
ctx.throw(500, 'Password error');
|
||||
}
|
||||
const token = await user.createToken();
|
||||
ctx.res.cookie('token', token.token, {
|
||||
maxAge: token.expireTime,
|
||||
domain: 'xiongxiao.me',
|
||||
sameSite: 'lax',
|
||||
httpOnly: true,
|
||||
});
|
||||
ctx.body = token;
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'user',
|
||||
key: 'logout',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
ctx.res.cookie('token', '', {
|
||||
maxAge: 0,
|
||||
domain: 'xiongxiao.me',
|
||||
sameSite: 'lax',
|
||||
httpOnly: true,
|
||||
});
|
||||
})
|
||||
.addTo(app);
|
||||
app
|
||||
.route('user', 'auth')
|
||||
.define(async (ctx) => {
|
||||
|
||||
Reference in New Issue
Block a user