import { useRef } from 'react'
import { appBridge } from '@shengkai/app-bridge'
export default function Main() {
const iframeRef = useRef<HTMLIFrameElement>(null)
const onLoad = () => {
appBridge.main({
data: {
user: '',
pwd: '',
},
iframe: iframeRef.current!,
})
}
return <iframe ref={iframeRef} src="http://172.168.18.250:5174" className="h-full w-full" onLoad={onLoad} />
}
import { appBridge } from '@shengkai/app-bridge'
appBridge.sub({
onMessage: async (data: {
user: string
pwd: string
}) => {
const res = await fetch('/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: data.user,
password: data.pwd,
}),
})
const json = await res.json()
localStorage.setItem('token', json.data.access_token)
},
})