first commit
This commit is contained in:
commit
db5762abd4
687 files changed
+171307
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { onBeforeUnmount } from "vue";
|
||||
import { ref } from "vue";
|
||||
import { useApi } from "~/lib/auth.js";
|
||||
import { r as oauth_r } from "~/lib/oauth.js";
|
||||
function i() {
|
||||
let i = useApi(),
|
||||
a = ref(!1),
|
||||
o = ref(``),
|
||||
s = !0;
|
||||
onBeforeUnmount(() => {
|
||||
s = !1;
|
||||
});
|
||||
async function c(e) {
|
||||
if (s && !a.value) {
|
||||
if (((o.value = ``), !/^[a-z][a-z0-9_]*$/i.test(e))) {
|
||||
o.value = `授权方式无效`;
|
||||
return;
|
||||
}
|
||||
a.value = !0;
|
||||
try {
|
||||
let t = await i.get(`/oauth/${encodeURIComponent(e)}`);
|
||||
if (!s) return;
|
||||
let n = oauth_r(t?.url, window.location.origin);
|
||||
if (!n) throw Error(`授权地址无效,请联系支持`);
|
||||
try {
|
||||
sessionStorage.setItem(`console-oauth-pending`, `1`);
|
||||
} catch {}
|
||||
window.location.assign(n);
|
||||
} catch (e) {
|
||||
s && (o.value = e instanceof Error ? e.message : `授权失败`);
|
||||
} finally {
|
||||
s && (a.value = !1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
busy: a,
|
||||
error: o,
|
||||
start: c,
|
||||
};
|
||||
}
|
||||
export { i as t };
|
||||
Reference in new issue
Block a user