E
E
Evgeny Romashkan2018-03-21 23:29:18
In contact with
Evgeny Romashkan, 2018-03-21 23:29:18

Anonymous function does not work in onAuth(Authorization Widget from VK)?

I made an authorization widget for an empty site on a local server ( https://vk.com/dev/Login?aid=6418856&mode=2).
Without changing anything copy-pasted their suggested embed code

<script type="text/javascript" src="//vk.com/js/api/openapi.js?152"></script>
<script type="text/javascript">
  VK.init({apiId: 6418856});
</script>

<!-- VK Widget -->
<div id="vk_auth"></div>
<script type="text/javascript">
  VK.Widgets.Auth("vk_auth", {"onAuth":"function(data) {alert('user '+data['uid']+' authorized');}"});
</script>

And it doesn't work. An error is displayed in the Console:
Uncaught TypeError: options.onAuth is not a function
at Server.makeAuth (openapi.js?152:1630)
at openapi.js?152:115
Here is the piece of code in openapi.js where the error occurs:
if (options.onAuth) {
        options.onAuth(data);
      }

If you replace the anonymous function with, for example:
VK.Widgets.Auth("vk_auth", {"onAuth":alert(1)}); then everything works fine.
What's the problem with anonymous function?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Romashkan, 2018-03-21
@EvgeniiR

UPD: I fiddled with this problem for two hours. It turned out that in the line
Quotes are not needed after the onAuth parameter, i.e. just like this:
Why VK does not give a working example is a question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question