wip
This commit is contained in:
parent
8471ff8eaf
commit
81b9e4dd68
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
|
coverage
|
||||||
dist
|
dist
|
||||||
node_modules
|
node_modules
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
node_modules
|
node_modules
|
||||||
|
coverage
|
||||||
src
|
src
|
||||||
.gitignore
|
.gitignore
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
4565
package-lock.json
generated
4565
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -7,8 +7,8 @@ export interface ITokenService {
|
|||||||
generate(
|
generate(
|
||||||
session: ISession,
|
session: ISession,
|
||||||
subject: string,
|
subject: string,
|
||||||
expires: string,
|
expires?: string,
|
||||||
algorithm: Algorithm
|
algorithm?: Algorithm
|
||||||
): Promise<string>;
|
): Promise<string>;
|
||||||
validate(token: string): Promise<boolean>;
|
validate(token: string): Promise<boolean>;
|
||||||
getAccount(token: string): Promise<IAccount | null>;
|
getAccount(token: string): Promise<IAccount | null>;
|
||||||
|
|||||||
@ -18,7 +18,11 @@ export class LoginService {
|
|||||||
private readonly accountService: AccountService
|
private readonly accountService: AccountService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async signIn(signIn: ISignIn): Promise<string> {
|
async signIn(
|
||||||
|
signIn: ISignIn,
|
||||||
|
expires: string = "1h",
|
||||||
|
algorithm: tokenService.Algorithm = "HS512"
|
||||||
|
): Promise<string> {
|
||||||
const accounts = await this.accountService.getBy(
|
const accounts = await this.accountService.getBy(
|
||||||
(x) =>
|
(x) =>
|
||||||
x.accountName === signIn.accountName &&
|
x.accountName === signIn.accountName &&
|
||||||
@ -35,7 +39,12 @@ export class LoginService {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
const session = await this.sessionService.create(accounts[0]);
|
const session = await this.sessionService.create(accounts[0]);
|
||||||
const token = await this.tokenService.generate(session);
|
const token = await this.tokenService.generate(
|
||||||
|
session,
|
||||||
|
signIn.accountName,
|
||||||
|
expires,
|
||||||
|
algorithm
|
||||||
|
);
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user