MCPcopy Index your code
hub / github.com/refined-github/refined-github / validateToken

Function validateToken

source/options/token-validation.tsx:46–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44}
45
46async function validateToken(): Promise<void> {
47 const tokenField = $('input[name="personalToken"]');
48 reportStatus();
49
50 if (!tokenField.validity.valid || tokenField.value.length === 0) {
51 // The Chrome options iframe auto-sizer causes the "scrollIntoView" function to scroll incorrectly unless you wait a bit
52 // https://github.com/refined-github/refined-github/issues/6807
53 setTimeout(expandTokenSection, 100);
54 return;
55 }
56
57 reportStatus({text: 'Validating…'});
58
59 try {
60 const base = getApiUrl();
61 const [tokenInfo, user] = await Promise.all([
62 getTokenInfo(base, tokenField.value),
63 tokenUser.get(base, tokenField.value),
64 ]);
65
66 // Build status message with user and expiration
67 let statusMessage = `👤 @${user}`;
68 if (tokenInfo.expiration) {
69 const msUntilExpiration = new Date(tokenInfo.expiration).getTime() - Date.now();
70 const daysUntilExpiration = Math.ceil(msUntilExpiration / (1000 * 60 * 60 * 24));
71 statusMessage += `, expires ${rtf.format(daysUntilExpiration, 'day')}`;
72 } else {
73 statusMessage += ', no expiration';
74 }
75
76 reportStatus({
77 text: statusMessage,
78 scopes: tokenInfo.scopes,
79 });
80 } catch (error) {
81 assertError(error);
82 reportStatus({error: true, text: error.message});
83 expandTokenSection();
84 throw error;
85 }
86}
87
88export default async function initTokenValidation(syncedForm: SyncedForm | undefined): Promise<void> {
89 await validateToken();

Callers 1

initTokenValidationFunction · 0.85

Calls 5

reportStatusFunction · 0.85
getApiUrlFunction · 0.85
getTokenInfoFunction · 0.85
expandTokenSectionFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected