mirror of
https://github.com/lucaspalomodevelop/auth-tools.git
synced 2026-03-12 22:07:22 +00:00
add isLoggedIn function
This commit is contained in:
parent
04e27a0db9
commit
7432031cd0
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@auth-tools/client",
|
||||
"version": "0.0.1-alpha.5",
|
||||
"version": "0.0.1-alpha.6",
|
||||
"description": "A structured authentication protocol for Javascript. (client)",
|
||||
"main": "dist/index.js",
|
||||
"repository": "https://github.com/auth-tools/auth-tools",
|
||||
|
||||
@ -15,7 +15,7 @@ import { createLogout } from "./methods/logout";
|
||||
import { createRefresh } from "./methods/refresh";
|
||||
import { createCheck } from "./methods/check";
|
||||
|
||||
type MethodReturn<MethodName extends keyof AuthProtocol> =
|
||||
export type MethodReturn<MethodName extends keyof AuthProtocol> =
|
||||
| { clientError: true; res: null }
|
||||
| { clientError: false; res: AuthResponse<MethodName> };
|
||||
|
||||
@ -88,4 +88,21 @@ export class AuthClient extends AuthBase<
|
||||
check: createCheck(this._internal),
|
||||
};
|
||||
}
|
||||
|
||||
//check if user is logged in
|
||||
public async isLoggedIn(): Promise<boolean> {
|
||||
const checkResponse = await (
|
||||
this._internal.config.connector as AuthClientConnector<"check">
|
||||
)("check", {});
|
||||
|
||||
if (checkResponse.clientError) return false;
|
||||
if (!checkResponse.res.error) return true;
|
||||
|
||||
const refreshResponse = await (
|
||||
this._internal.config.connector as AuthClientConnector<"refresh">
|
||||
)("refresh", {});
|
||||
|
||||
if (refreshResponse.clientError) return false;
|
||||
return !refreshResponse.res.error;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user