<?php

namespace App\Http\Controllers\Chat;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ClientController extends Controller
{
    public function __construct()
    {
        $this->middleware('authed');
    }

    public function index(Request $request)
    {
        $user = $request->user();
        $userInfo = null;

        if($user) {
            $userInfo = base64_encode(json_encode([
                'sid' => $user->sid,
                'email' => $user->email,
                'name' => $user->name,
                'nickname' => $user->nickname,
                'level' => $user->level,
                'icon' => $user->icon,
                'thumb' => $user->thumb,
                'token' => $request->session()->get('token')
            ]));
        }

        return view('chat.index', [
            'userInfo' => $userInfo
        ]);
    }
}
