Slide 17
Slide 17 text
Example of Plugin Feature : Case2
// Plugin's code (liffp-login-your-service.js)
export default class {
get name() { return “yourService" }
install(ctx, liff) {
ctx.addCallback("afterLogin", () => {
// Send AccessToken to your server
this.userInfo = await fetch("https://yourapp.com/userInfo", {
method: "POST",
headers: { Authorization: `Bearer ${liff.getAccessToken()}` }
}).then(res => res.json())
})
return {
// Register your API
getAccountId() {
return this.userInfo.AccountId
}
}
}
}
// Plugin user's code (main.js)
import LoginYourService from 'liffp-login-your-service.js'
const loginYourService = new LoginYourService()
liff.use(loginYourService)
liff.init({liffId: "YOUR LIFF ID"}).then(() => {
// User can call your API
const yourSerivceLoginId = liff.$yourService.getAccountId()
})