made .env file work
This commit is contained in:
parent
05f2565071
commit
74e7ac1d4c
10
auth/.env
10
auth/.env
|
@ -1,5 +1,5 @@
|
|||
version: '3'
|
||||
services:
|
||||
your-service:
|
||||
environment:
|
||||
- JWT_SECRET_KEY=your_actual_secret_key
|
||||
# .env
|
||||
|
||||
DATABASE_URL=postgres://username:password@localhost/mydatabase
|
||||
JWT_SECRET_KEY=qd9NLicyHJNF9A85IrE72a4GL5Rrk6rQzbERvYn6Z7BZN0SrlLZQWruJCcIRXEh4GKH_WyXquzUGTs4zvh65L84B9ZCg7r99257U2yu1WzhF8mpj7uZ06j9jBNTBvCgNO3qemh-kd4XjekpYZ9Et38T1sgksPFpF5w99gOLsHm3iUfIqa-slTplGQr3rzqIy_9HJAXv66lmx12XOAYEWv9cISIHVp6itL8v7pl38dqn0RoYGJxc2f6BHKpNzESGrsmg-xQztfkRw-EtoDEIBEdBEvitc_h2ilj2Dm2dVaEYR41jlBrWsuCi13c0EWh_N5hq37U7rOQzZwFhzAKzujw
|
||||
API_KEY=your_api_key
|
|
@ -13,6 +13,6 @@ gem 'bcrypt'
|
|||
gem 'securerandom'
|
||||
gem 'json'
|
||||
gem 'multipart-post'
|
||||
|
||||
gem 'dotenv'
|
||||
|
||||
# bundle install
|
|
@ -2,6 +2,7 @@ GEM
|
|||
remote: https://rubygems.org/
|
||||
specs:
|
||||
bcrypt (3.1.20)
|
||||
dotenv (2.8.1)
|
||||
json (2.7.1)
|
||||
jwt (2.7.1)
|
||||
multipart-post (2.3.0)
|
||||
|
@ -26,6 +27,7 @@ PLATFORMS
|
|||
|
||||
DEPENDENCIES
|
||||
bcrypt
|
||||
dotenv
|
||||
json
|
||||
jwt
|
||||
multipart-post
|
||||
|
|
29
auth/auth.rb
29
auth/auth.rb
|
@ -9,31 +9,10 @@ require 'sinatra'
|
|||
require 'json'
|
||||
require 'sqlite3'
|
||||
require 'jwt'
|
||||
require 'dotenv/load'
|
||||
|
||||
TOKEN_SECRET = 'WChX-tQWbGbj_pGJQREoFAZGC9JWh58KSk8O7KPj-P8Nd-J88g3eSFDVuNe6zddj0ZB3yxjm_IuPNPyLhiSnxlWHImqXR6ajh3OzrzYm0bNb3f5C4IAScphyEdAfYGMcM-HvYOXxxxp5u5mryfiV3JH1CTqL1CzGyO8df7zUpRKXEXZ5SKmUvhfLU0XKCR_28FAZUgPCAi3GywkDDsH0by68j33BU5cnMT8KiEkHOX4wVUVDQc85_AuE7fN3ji_WkhnDCSLXU9dBCcXM3ziFFeX0RbvIRDG0vKdzwt4TOr4Jws7NP9w11GrUGDFKARZqvT7FTxwxO3MM-mmjb2xyGg'
|
||||
|
||||
set :public_folder, DATA_LOCATION + FILE_STORAGE_LOCATION
|
||||
|
||||
#puts generate_random_string(256)
|
||||
|
||||
|
||||
#
|
||||
#token = JWT.encode payload, hmac_secret, 'HS256'
|
||||
##puts token
|
||||
#
|
||||
#begin
|
||||
# decoded_token = JWT.decode token, hmac_secret, true, { algorithm: 'HS256' }
|
||||
# puts "Token is valid!"
|
||||
# puts "Decoded token: #{decoded_token}"
|
||||
#
|
||||
# puts data_value = decoded_token.first['data']
|
||||
# puts test_value = decoded_token.first['test']
|
||||
#rescue JWT::DecodeError
|
||||
# puts "Invalid token or signature!"
|
||||
#end
|
||||
|
||||
#puts decoded_token
|
||||
|
||||
TOKEN_SECRET = ENV['JWT_SECRET_KEY']
|
||||
puts TOKEN_SECRET
|
||||
initialize_database
|
||||
|
||||
post '/auth/login' do
|
||||
|
@ -79,9 +58,9 @@ post '/auth/reauthenticate' do
|
|||
|
||||
# At this point, the token is valid
|
||||
# You can access the claims inside the 'decoded_token' variable
|
||||
|
||||
uid = decoded_token.first['uid']
|
||||
|
||||
|
||||
# Your reauthentication logic here...
|
||||
|
||||
# Return a response (replace with your own logic)
|
||||
|
|
|
@ -7,7 +7,6 @@ def initialize_database
|
|||
|
||||
database_path = DATA_LOCATION + DATABASE_SUBPATH
|
||||
file_path = DATA_LOCATION + FILE_STORAGE_LOCATION
|
||||
puts database_path
|
||||
|
||||
unless File.directory?(DATA_LOCATION)
|
||||
Dir.mkdir(DATA_LOCATION)
|
||||
|
|
Loading…
Reference in New Issue