/ examples / cas / login.mts
login.mts
 1  import { CAS } from "unilim/cas";
 2  
 3  const auth = await CAS.initialize(
 4    Bun.env.USERNAME!,
 5    Bun.env.PASSWORD!
 6  );
 7  
 8  if (!auth.solved) {
 9    if (auth.isTotpAvailable) {
10      const totp = prompt("totp>");
11      if (!totp) process.exit(0);
12  
13      await auth.solveWithTotp(totp);
14    }
15    else if (auth.isEmailAvailable) {
16      await auth.sendEmailCode();
17  
18      const code = prompt("code>");
19      if (!code) process.exit(0);
20  
21      await auth.solveWithEmailCode(code);
22    }
23  }
24  
25  const cas = await auth.finish();
26  
27  console.log("You're authenticated! Here's your restore auth details.");
28  console.log("- CONNECTION:", cas.connection);
29  console.log("- KEY:", cas.key);
30  
31  console.log("Oh and also, here's your current session cookie.");
32  console.log("- COOKIE:", cas.cookie);