People have suggested how you can do this. Here is one practical solution.
As mentioned, you write a script that does your session checking and redirects with a header() call to whatever error handling solution you want.
I would not advocate you call the script js.js.php. In general you don't want to allow files with somename.somename.ext due to intrinsic issues with apache.
So instead, simply name your script js.js. However, the source for js.js should be php code that does the session check, and if ok, returns the javascript source, with the appropriate mime type header.
Then in your htaccess for the directory you can add a custom Files rule:
<Files js.js>
SetHandler application/x-httpd-php
</Files>
Apache will then treat js.js as a php file, even though this functionality is otherwise invisible.