frontend/.pnpm-store/v3/files/74/2e3c467aa3392706138225f170edc0e1d1292441194e74da849566796e2382e2281dc597981ebcb44324e00424009e7f84d9117a342bab8df6ae4a84630526

22 lines
665 B
Plaintext

const REGEX_IS_INSTALLATION_LEGACY = /^v1\./;
const REGEX_IS_INSTALLATION = /^ghs_/;
const REGEX_IS_USER_TO_SERVER = /^ghu_/;
export async function auth(token) {
const isApp = token.split(/\./).length === 3;
const isInstallation = REGEX_IS_INSTALLATION_LEGACY.test(token) ||
REGEX_IS_INSTALLATION.test(token);
const isUserToServer = REGEX_IS_USER_TO_SERVER.test(token);
const tokenType = isApp
? "app"
: isInstallation
? "installation"
: isUserToServer
? "user-to-server"
: "oauth";
return {
type: "token",
token: token,
tokenType,
};
}