<?php

namespace App\Controllers;

use App\Traits\ResponseTrait;
use CodeIgniter\Controller;

use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Firebase\JWT\ExpiredException;
use Firebase\JWT\SignatureInvalidException;
use Firebase\JWT\BeforeValidException;
use CodeIgniter\Cookie\Cookie;

class SampleController extends Controller {
    use ResponseTrait;

    public function index() {

        $token = $this->request->getCookie('token');
        $key   = getenv('JWT_SECRET');

        // Decode Token dengan Key yg ada di .env
        $decodedPayload = JWT::decode($token, new Key($key, 'HS256'));

        return $this->respond([
            'status'  => 'success',
            'code'    => 200,
            'message' => 'Authenticated',
            'data'    => $decodedPayload
        ], 200);
    }
    
}
