mirror of https://github.com/msgbyte/tailchat
feat: github oauth login view
parent
ed1d7cc1d6
commit
e81e7ad64f
@ -0,0 +1,54 @@
|
||||
import React from 'react';
|
||||
import { useAsync } from '@capital/common';
|
||||
import { Divider, Image, Tooltip } from '@capital/component';
|
||||
import { request } from './request';
|
||||
|
||||
export const FimAction: React.FC = React.memo(() => {
|
||||
const { loading, value: strategies } = useAsync(async () => {
|
||||
const { data: strategies } = await request.get('availableStrategies');
|
||||
|
||||
return strategies;
|
||||
}, []);
|
||||
|
||||
if (loading) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Array.isArray(strategies) && strategies.length > 0) {
|
||||
return (
|
||||
<div>
|
||||
<Divider />
|
||||
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
||||
{strategies.map((s) => (
|
||||
<Tooltip key={s.name} title={s.name}>
|
||||
<Image
|
||||
style={{
|
||||
width: 40,
|
||||
height: 40,
|
||||
cursor: 'pointer',
|
||||
borderRadius: 20,
|
||||
}}
|
||||
src={s.icon}
|
||||
onClick={async () => {
|
||||
if (s.type === 'oauth') {
|
||||
const { data: url } = await request.get(
|
||||
`${s.name}.loginUrl`
|
||||
);
|
||||
|
||||
const win = window.open(url, 'square', 'frame=true');
|
||||
win.addEventListener('message', (...args) => {
|
||||
console.log(...args);
|
||||
});
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
FimAction.displayName = 'FimAction';
|
@ -1 +1,9 @@
|
||||
import { regLoginAction } from '@capital/common';
|
||||
import { FimAction } from './FimAction';
|
||||
|
||||
console.log('Plugin Federated Identity Management is loaded');
|
||||
|
||||
regLoginAction({
|
||||
name: 'fim',
|
||||
component: FimAction,
|
||||
});
|
||||
|
@ -0,0 +1,3 @@
|
||||
import { createPluginRequest } from '@capital/common';
|
||||
|
||||
export const request = createPluginRequest('com.msgbyte.fim');
|
Loading…
Reference in New Issue