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

How to use custom autorization without nuxt/auth module? #60

Open
mrmmg opened this issue Oct 6, 2021 · 1 comment
Open

How to use custom autorization without nuxt/auth module? #60

mrmmg opened this issue Oct 6, 2021 · 1 comment

Comments

@mrmmg
Copy link

mrmmg commented Oct 6, 2021

Hi

Thanks for your good package, I'm using laravel as backend API (with passport package) and I have some issues with your package, please help me to solve this. let me explain it to you:

I have laravel as backend in the localhost:8000 domain and have a nuxtJS project in the localhost:3000. I'm making a login request from nuxt application to laravel with Axios and save user tokens in cookies.

now when I want to subscribe to private or presence channel I get 401 and it's because of that I cannot set the header for broadcasting/auth endpoint. remember I saved user token in browser cookies.

in nuxt.config.js file i have these options for echo:

echo: {
    broadcaster: 'pusher',
    host: '127.0.0.1:6001',
    wsHost: '127.0.0.1',
    wsPort: 6001,
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: 'mt1',
    forceTLS: false,
    encrypted: false,
    disableStats: true,
    authEndpoint: 'http://127.0.0.1:8000/broadcasting/auth',
    auth: {
       headers: {
            Authorization: `Bearer ${cookies.get('user_token')}`           // i'm using js-cookie package to works with cookies
       }
    }
  },

And in Laravel:

in BroadcastServiceProvider:

 public function boot()
    {
        Broadcast::routes(['middleware' => 'auth:api']);

        require base_path('routes/channels.php');
    }

in my event file:

public function broadcastOn()
    {
        return new PresenceChannel('user.messages.chat.' . $this->user_id);
    }

in controller file:

broadcast(new ApplicationChatMessage(json_encode($message), auth('api')->id()))->toOthers();

in routes/channel.php:

Broadcast::channel(
    'user.messages.{id}', //parameter 1
    function ($user, $id) {      //parameter 2
        return (int)$user->id === (int)$id;
    }); 

But it's RETURN 401.

are you can help me to solve this issue?

@SilvioDoMine
Copy link

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants