首页 > 解决方案 > Laravel Socialite 如何在重定向到提供者后将变量保留在会话中

问题描述

欢迎
我正在开发一个多语言网站,我目前正在使用社交媒体(Socialite)登录
问题是:
在使用谷歌登录之前,我locale在会话中保存了一个变量('en','fr'.. etc) . 但是在登录并从 Google 重定向到我的网站后,我发现我在会话中放入的变量的值是null
使用以下代码

    /* this method will redirect user from my website to google for auth */
    public function redirectToGoogleProvider()
    {
        Session::put("locale", app()->getLocale());
        return Socialite::driver('google')->redirect();
    }

    /* this method will called when auth finished */
    public function handleGoogleProviderCallback()
    {
        $locale = Session::get('locale');
        dd($locale); // output: null
    }

编辑:我在使用cookie 谢谢时遇到了同样的问题。

标签: phplaravelsessionlaravel-socialite

解决方案


推荐阅读