Skip to content

Commit 2530626

Browse files
committed
Implement logout field.
1 parent f235227 commit 2530626

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/Field/Auth/LogoutField.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace ProcessWire\GraphQL\Field\Auth;
4+
5+
use Youshido\GraphQL\Field\AbstractField;
6+
use Youshido\GraphQL\Config\Field\FieldConfig;
7+
use Youshido\GraphQL\Type\NonNullType;
8+
use Youshido\GraphQL\Execution\ResolveInfo;
9+
use ProcessWire\GraphQL\Type\Object\AuthResponseType;
10+
use ProcessWire\WireData;
11+
use ProcessWire\Session;
12+
13+
class LogoutField extends AbstractField {
14+
15+
public function getType()
16+
{
17+
return new NonNullType(new AuthResponseType());
18+
}
19+
20+
public function getName()
21+
{
22+
return 'logout';
23+
}
24+
25+
public function getDescription()
26+
{
27+
return 'Allows you to logout from the app.';
28+
}
29+
30+
public function resolve($value, array $args, ResolveInfo $info)
31+
{
32+
$session = \ProcessWire\wire('session');
33+
$session = $session->logout();
34+
$response = new WireData();
35+
if ($session instanceof Session) {
36+
$response->statusCode = 200;
37+
$response->message = 'Successful logout!';
38+
} else {
39+
$response->statusCode = 500;
40+
$response->message = 'Could not logout.';
41+
}
42+
return $response;
43+
}
44+
45+
}

0 commit comments

Comments
 (0)