saya lagi ngikut tutorial rest api codeigniter di playlist sekolah koding, nah di saat di bagian check token saya mendapat error saat ingin mendecode token Hasil dari Postman : Routes :Controller :load->model('user'); } public function response($data) { $this->output ->set_content_type('application/json') ->set_status_header(200) ->set_output(json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)) ->_display(); exit; } public function register() { return $this->response($this->user->save()); } public function get_all() { return $this->response($this->user->get()); } public function get($id) { return $this->response($this->user->get('id', $id)); } public function login() { $date = new DateTime(); if (!$this->user->is_valid()) { return $this->response([ 'success' => false, 'message' => 'email atau password salah' ]); } $user = $this->user->get('email', $this->input->post('email')); // encode data $payload['id'] = $user->id; $payload['iat'] = $date->getTimestamp(); $payload['exp'] = $date->getTimestamp() + 60 * 60 * 2; $output['id_token'] = JWT::encode($payload, $this->secret); $this->response($output); } public function check_token() { $jwt = $this->input->get_request_header('Authorization'); try { $decoded = JWT::decode($jwt, $this->secret, array('HS256')); var_dump($decoded); } catch (\Exception $e) { // return $this->response([ // 'success' => false, // 'message' => 'gagal, error token' // ]); var_dump($e); } } public function delete($id) { // check user login $this->check_token(); // orang yang login yg mau hapus } }Models :$this->input->post('email'), 'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT), ]; if ($this->db->insert('users', $data)) { return [ 'id' => $this->db->insert_id(), 'success' => true, 'message' => 'data berhasil dimasukan' ]; } } public function get($key = null, $value = null) { if ($key != null) { $query = $this->db->get_where('users', array($key => $value)); return $query->row(); } $query = $this->db->get('users'); return $query->result(); } public function is_valid() { $email = $this->input->post('email'); $password = $this->input->post('password'); $hash = $this->get('email', $email)->password; if (password_verify($password, $hash)) return true; return false; } } |