electron client auto login
This commit is contained in:
parent
f5464b1507
commit
8d072c82c6
11
app.ts
11
app.ts
@ -1,6 +1,7 @@
|
||||
import { app, BrowserWindow } from "electron";
|
||||
import { app, BrowserWindow, session } from "electron";
|
||||
import { get_setting } from "./src/setting";
|
||||
import { create_server, start_server } from "./src/server";
|
||||
import { getAdminCookieValue } from "./src/login";
|
||||
|
||||
const get_loading_html = (content?:string)=> `<!DOCTYPE html>
|
||||
<html lang="ko"><head>
|
||||
@ -46,6 +47,14 @@ if (!setting.cli) {
|
||||
useContentSize: true,
|
||||
});
|
||||
await window.loadURL(`data:text/html;base64,`+Buffer.from(get_loading_html()).toString('base64'));
|
||||
await session.defaultSession.cookies.set({
|
||||
url:`http://localhost:${setting.port}`,
|
||||
name:"access_token",
|
||||
value:getAdminCookieValue(),
|
||||
httpOnly: true,
|
||||
secure: false,
|
||||
sameSite:"strict"
|
||||
});
|
||||
try{
|
||||
const server = await create_server();
|
||||
start_server(server);
|
||||
|
@ -1 +0,0 @@
|
||||
{"path":[],"localmode":true,"guest":false,"jwt_secretkey":"itsRandom","port":8080,"mode":"production","cli":true}
|
@ -10,6 +10,15 @@ import { IUser } from './model/mod';
|
||||
|
||||
const loginTokenName = 'access_token'
|
||||
|
||||
export const getAdminCookieValue = ()=>{
|
||||
const setting = get_setting();
|
||||
const secretKey = setting.jwt_secretkey;
|
||||
return sign({
|
||||
username: "admin",
|
||||
permission: []
|
||||
},secretKey,{expiresIn:'3d'});
|
||||
}
|
||||
|
||||
export const createLoginMiddleware = (knex: Knex)=>{
|
||||
const userController = createKnexUserController(knex);
|
||||
return async (ctx: Koa.Context,next: Koa.Next)=>{
|
||||
|
Loading…
Reference in New Issue
Block a user