-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use endpoint from .dicorc or fallback to production
- Loading branch information
Showing
6 changed files
with
82 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { CAC } from "cac"; | ||
import { logger } from "../lib"; | ||
import * as dicorc from "../core/dicorc"; | ||
import * as user from "../core/user"; | ||
|
||
export const signout = (_: CAC, __: { [key: string]: never }): void => { | ||
dicorc.signout(); | ||
user.signout(); | ||
console.log(""); | ||
logger.success("Logged out\n"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as client from "./client"; | ||
import * as dicorc from "./dicorc"; | ||
|
||
/** | ||
* Sign in used | ||
*/ | ||
export const signin = async ( | ||
token: string | ||
): Promise<Required<dicorc.Config>["user"]> => { | ||
const user = await client.whoami(token); | ||
|
||
dicorc.update({ user }); | ||
|
||
return user; | ||
}; | ||
|
||
/** | ||
* Sign out user | ||
*/ | ||
export const signout = (): void => { | ||
const config = dicorc.read(); | ||
|
||
delete config.user; | ||
|
||
dicorc.write(config); | ||
}; | ||
|
||
/** | ||
* Check if user is signed in | ||
*/ | ||
export const isSignedIn = async (): Promise<boolean> => { | ||
const config = dicorc.read(); | ||
|
||
if (!config.user) { | ||
return false; | ||
} | ||
|
||
// Invalid token | ||
if (config.user.token.length !== 64) { | ||
signout(); | ||
|
||
return false; | ||
} | ||
|
||
try { | ||
await client.whoami(config.user.token); | ||
} catch (error) { | ||
throw error; | ||
} | ||
|
||
return true; | ||
}; |