Skip to content

Commit

Permalink
Use meta tag CSRF and not window.csrfToken (#49)
Browse files Browse the repository at this point in the history
* Use meta tag CSRF and not window.csrfToken

* Typo - my bad it should use .content instead of .value
  • Loading branch information
fdocr committed Mar 1, 2022
1 parent f366039 commit 8926bba
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/ForemWebView/ForemWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ open class ForemWebView: WKWebView {

// Function that fetches the CSRF Token required for direct interaction with the Forem servers
func fetchCSRF(completion: @escaping (String?) -> Void) {
evaluateJavaScript(wrappedJS("window.csrfToken")) { result, error in
let javascript = "document.querySelector(`meta[name='csrf-token']`)?.content"
evaluateJavaScript(wrappedJS(javascript)) { result, error in
if let error = error {
print("Unable to fetch CSRF Token: \(error.localizedDescription)")
completion(nil)
Expand Down

0 comments on commit 8926bba

Please sign in to comment.