Arc Forumnew | comments | leaders | submitlogin
How can I store a cookie without a login?
1 point by lark 4261 days ago | 5 comments
I would like to store a cookie on the user's browser without requiring the user to login. How do I do that?


1 point by lark 4261 days ago | link

It seems I need something like this:

  (defop-raw some-fancy-url (str req)
    (w/stdout str
              (anon-login req)
              (prn)
              (some-fancy-url-handler req)))

  (def anon-login (req)
       (if (no (get-user req))
           (withs (user (makeid 14)
                        cookie (cook-user user))
                  (= (logins* user) req!ip)
                  (prcookie cookie)
                  (prn)
                  (save-table cookie->user* cookfile*)
                  (user->cookie* user)
                  )))

  (def some-fancy-url-handler (req)
    (pr "Hello World"))

  ;; And visit /some-fancy-url

-----

2 points by thaddeus 4258 days ago | link

If its just a one off thing then you could just emit/print raw JavaScript outputting the document onload function to trigger the storing or updating of your cookie (you could also build arc wrapper functions too).

I.e Document.Onload -> Document.Cookie

-----

2 points by lark 4253 days ago | link

These two lines are not needed:

             (save-table cookie->user* cookfile*)
             (user->cookie* user)
And replace

  makeid
with

  rand-string

-----

1 point by akkartik 4253 days ago | link

Thanks a lot!

-----

1 point by akkartik 4261 days ago | link

Yeah that seems plausible. I guess I don't understand what you're asking.

Perhaps it'll help to tell us more about what you're building and what you're trying to do and why.

-----