<?php
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
function make_jwt($payload){
    $now = time();
    $exp = $now + (60*60*24); // 24h
    $secret = $_ENV['JWT_SECRET'] ?? 'secret';
    $token = array_merge(['iat'=>$now,'exp'=>$exp], $payload);
    return JWT::encode($token, $secret, 'HS256');
}
function verify_jwt($token){
    $secret = $_ENV['JWT_SECRET'] ?? 'secret';
    try{
        $decoded = JWT::decode($token, new Key($secret, 'HS256'));
        return (array)$decoded;
    }catch(Exception $e){
        return false;
    }
}
