This plugin implements Telegram WebApp Auth and Telegram Login Widget for the pocketbase
- Go 1.18+
- Pocketbase 0.12+
go get github.com/iamelevich/pocketbase-plugin-telegram-auth
name
- stringfirst_name
- stringlast_name
- stringtelegram_username
- stringtelegram_id
- stringlanguage_code
- string
You can check examples in examples folder
package main
import (
tgAuthPlugin "github.com/iamelevich/pocketbase-plugin-telegram-auth"
"log"
"github.com/pocketbase/pocketbase"
)
func main() {
app := pocketbase.New()
// Setup tg auth for users collection
tgAuthPlugin.MustRegister(app, &tgAuthPlugin.Options{
BotToken: "YOUR_SUPER_SECRET_BOT_TOKEN", // Better to use ENV variable for that
CollectionKey: "users",
})
if err := app.Start(); err != nil {
log.Fatal(err)
}
}
After that new route POST /api/collections/users/auth-with-telegram
will be available.
Simple usage with js. You can check react example here
const pb = new PocketBase('http://127.0.0.1:8090');
pb.send('/api/collections/users/auth-with-telegram', {
method: 'POST',
body: {
data: window.Telegram.WebApp.initData
}
}).then(res => {
pb.authStore.save(res.token, res.record);
});
This pocketbase plugin is free and open source project licensed under the MIT License. You are free to do whatever you want with it, even offering it as a paid service.