Skip to content

Commit 73f3269

Browse files
committed
feat: only use middleware when in leaf app
1 parent 79c7842 commit 73f3269

1 file changed

Lines changed: 44 additions & 42 deletions

File tree

src/Auth.php

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,53 +45,55 @@ class Auth
4545

4646
public function __construct()
4747
{
48-
$this->middleware('auth.required', function () {
49-
response()->redirect('/auth/login');
50-
});
51-
52-
$this->middleware('auth.guest', function () {
53-
response()->redirect('/dashboard');
54-
});
55-
56-
$this->middleware('is', function ($role) {
57-
\Leaf\Exception\General::error(
58-
'404',
59-
'<p>The page you are looking for could not be found.</p>',
60-
403
61-
);
62-
});
48+
if (class_exists('Leaf\App')) {
49+
$this->middleware('auth.required', function () {
50+
response()->redirect('/auth/login');
51+
});
6352

64-
$this->middleware('isNot', function () {
65-
\Leaf\Exception\General::error(
66-
'404',
67-
'<p>The page you are looking for could not be found.</p>',
68-
403
69-
);
70-
});
53+
$this->middleware('auth.guest', function () {
54+
response()->redirect('/dashboard');
55+
});
7156

72-
$this->middleware('can', function () {
73-
\Leaf\Exception\General::error(
74-
'404',
75-
'<p>The page you are looking for could not be found.</p>',
76-
403
77-
);
78-
});
57+
$this->middleware('is', function ($role) {
58+
\Leaf\Exception\General::error(
59+
'404',
60+
'<p>The page you are looking for could not be found.</p>',
61+
403
62+
);
63+
});
7964

80-
$this->middleware('cannot', function () {
81-
\Leaf\Exception\General::error(
82-
'404',
83-
'<p>The page you are looking for could not be found.</p>',
84-
403
85-
);
86-
});
65+
$this->middleware('isNot', function () {
66+
\Leaf\Exception\General::error(
67+
'404',
68+
'<p>The page you are looking for could not be found.</p>',
69+
403
70+
);
71+
});
8772

88-
$this->middleware('auth.verified', function () {
89-
response()->redirect('/auth/verify');
90-
});
73+
$this->middleware('can', function () {
74+
\Leaf\Exception\General::error(
75+
'404',
76+
'<p>The page you are looking for could not be found.</p>',
77+
403
78+
);
79+
});
80+
81+
$this->middleware('cannot', function () {
82+
\Leaf\Exception\General::error(
83+
'404',
84+
'<p>The page you are looking for could not be found.</p>',
85+
403
86+
);
87+
});
9188

92-
$this->middleware('auth.unverified', function () {
93-
response()->redirect('/dashboard');
94-
});
89+
$this->middleware('auth.verified', function () {
90+
response()->redirect('/auth/verify');
91+
});
92+
93+
$this->middleware('auth.unverified', function () {
94+
response()->redirect('/dashboard');
95+
});
96+
}
9597

9698
if (
9799
class_exists('League\OAuth2\Client\Provider\Google') &&

0 commit comments

Comments
 (0)