Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed LN auth to frontend #661

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions auth/lnurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package auth

import (
"crypto/rand"
"fmt"
"strings"

lnurl "github.com/fiatjaf/go-lnurl"
Expand All @@ -16,7 +15,6 @@ type LnEncodeData struct {
}

func EncodeLNURL(host string) (LnEncodeData, error) {
fmt.Println("Host ===", host)
hostUrl := config.Host
if !strings.Contains(host, "localhost") {
hostUrl = "https://" + host
Expand Down
4 changes: 4 additions & 0 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ type LnHost struct {
K1 string `json:"k1"`
}

type LnEncode struct {
Host string `json:"host"`
}

type BountyLeaderboard struct {
Owner_pubkey string `json:"owner_pubkey"`
Total_bounties_completed uint `json:"total_bounties_completed"`
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/config/ModeDispatcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export enum AppMode {
}

const hosts: { [k: string]: AppMode } = {
'localhost:3000': AppMode.TRIBES,
'localhost:3000wqwq': AppMode.TRIBES,
'localhost:13000': AppMode.TRIBES,
'localhost:23000': AppMode.TRIBES,
'tribes.sphinx.chat': AppMode.TRIBES,
Expand Down
4 changes: 3 additions & 1 deletion frontend/app/src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,9 @@ export class MainStore {

@action async getLnAuth(): Promise<LnAuthData> {
try {
const data = await api.get(`lnauth?socketKey=${uiStore.websocketToken}`);
const data = await api.post(`lnauth?socketKey=${uiStore.websocketToken}`, {
host: TribesURL
});
this.setLnAuth(data);
return data;
} catch (e) {
Expand Down
13 changes: 9 additions & 4 deletions handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package handlers
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -34,7 +34,7 @@ func CreateConnectionCode(w http.ResponseWriter, r *http.Request) {
code := db.ConnectionCodes{}
now := time.Now()

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
r.Body.Close()

err = json.Unmarshal(body, &code)
Expand Down Expand Up @@ -68,9 +68,14 @@ func GetConnectionCode(w http.ResponseWriter, _ *http.Request) {
func GetLnurlAuth(w http.ResponseWriter, r *http.Request) {
socketKey := r.URL.Query().Get("socketKey")
socket, _ := db.Store.GetSocketConnections(socketKey)
serverHost := r.Host

encodeData, err := auth.EncodeLNURL(serverHost)
hostData := db.LnEncode{}
body, err := io.ReadAll(r.Body)
r.Body.Close()

err = json.Unmarshal(body, &hostData)

encodeData, err := auth.EncodeLNURL(hostData.Host)
responseData := make(map[string]string)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion routes/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewRouter() *http.Server {

r.Group(func(r chi.Router) {
r.Get("/lnauth_login", handlers.ReceiveLnAuthData)
r.Get("/lnauth", handlers.GetLnurlAuth)
r.Post("/lnauth", handlers.GetLnurlAuth)
r.Get("/refresh_jwt", handlers.RefreshToken)
r.Post("/invoices", handlers.GenerateInvoice)
})
Expand Down
Loading