diff --git a/.env.template b/.env.template index 959dded..123b52b 100644 --- a/.env.template +++ b/.env.template @@ -1 +1 @@ -AUTH_COOKIE= \ No newline at end of file +NEXT_AUTH_CSRF_TOKEN= \ No newline at end of file diff --git a/main.go b/main.go index 8119159..22c6460 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( ) var ( - AuthCookie string + SnApiToken string ) func init() { @@ -16,17 +16,16 @@ func init() { if err != nil { log.Fatal("Error loading .env file") } - flag.StringVar(&AuthCookie, "auth_cookie", "", "Cookie required for authorization") + flag.StringVar(&SnApiToken, "NEXT_AUTH_CSRF_TOKEN", "", "Token required for authorizing requests to stacker.news/api/graphql") flag.Parse() - if AuthCookie == "" { - log.Fatal("auth cookie not set") + if SnApiToken == "" { + log.Fatal("NEXT_AUTH_CSRF_TOKEN not set") } } func main() { stories := fetchTopStoriesFromHN() filtered := filterByRelevanceForSN(&stories) - log.Println(filtered) for _, story := range *filtered { postToSN(&story) } diff --git a/sn.go b/sn.go index d5666f7..0722d2e 100644 --- a/sn.go +++ b/sn.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/json" + "fmt" "log" "net/http" ) @@ -47,7 +48,7 @@ func postToSN(story *Story) { panic(err) } req.Header.Set("Content-Type", "application/json") - req.Header.Set("Cookie", AuthCookie) + req.Header.Set("Cookie", fmt.Sprintf("__Host-next-auth.csrf-token=%s", SnApiToken)) client := http.DefaultClient resp, err := client.Do(req)