Skip to content

Commit e32dfa8

Browse files
author
Linus Juhlin
committed
WIP
1 parent 905e31f commit e32dfa8

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

components/auth/config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
'path' => '/',
122122
'domain' => null,
123123
'driver' => 'file',
124-
'files' => __DIR__ . '/sessions',
124+
'files' => __DIR__ . '/../sessions',
125125
'lifetime' => 120,
126126
'expire_on_close' => false,
127127
]

components/auth/index.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Illuminate\Http\Request;
1919
use Illuminate\Pipeline\Pipeline;
2020
use Illuminate\Session\SessionManager;
21+
use Symfony\Component\HttpFoundation\Cookie;
2122

2223
$container = App::getInstance();
2324

@@ -160,7 +161,6 @@
160161

161162
// Global middlewares
162163
$globalMiddleware = [
163-
\App\Middleware\StartSession::class,
164164
];
165165

166166
// Array middlewares
@@ -180,6 +180,19 @@
180180
// Create a request from server variables
181181
$request = Request::capture();
182182

183+
// In order to maintain the session between requests, we need to populate the
184+
// session ID from the supplied cookie
185+
$cookieName = $container['session']->getName();
186+
187+
if (isset($_COOKIE[$cookieName])) {
188+
if ($sessionId = $_COOKIE[$cookieName]) {
189+
$container['session']->setId($sessionId);
190+
}
191+
}
192+
193+
// Boot the session
194+
$container['session']->start();
195+
183196
// Dispatching the request:
184197
// When it comes to dispatching the request, you have two options:
185198
// a) you either send the request directly through the router
@@ -197,9 +210,16 @@
197210
return $router->dispatch($request);
198211
});
199212

213+
$response->headers->setCookie(new Cookie(
214+
$container['session']->getName(), $container['session']->getId(),
215+
));
216+
217+
$container['session']->save();
218+
200219
// Send the response back to the browser
201220
$response->send();
202221

222+
// Create your user
203223
// User::create([
204224
// 'email' => 'admin',
205225
// 'name' => 'admin',

components/auth/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
$router->group(['middleware' => 'auth'], function (Router $router) {
2020
$router->get('/', function () {
21-
return 'hello world!';
21+
return 'hello ' . \App::getInstance()['auth']->user()->name . '!';
2222
});
2323

2424
$router->get('bye', function () {

0 commit comments

Comments
 (0)