Copy the template .env.template
file to .env.local
and .env.production
.
cp .env.template .env.local
cp .env.template .env.production
.env.production
will need new values for every variable.
Then install dependencies and start the server.
yarn
yarn dev
In the root of the directory, there is a /data
folder. This is where the cached data from egghead-rails
api will live.
The first think you need to do is fill out /data/content.config.js
. This file indicates what bundles this site is selling. There is currently 2 expected bundles: a pro tier and a book tier. This can be adjusted to the specific site needs.
You can add NEXT_PUBLIC_PRO_SLUG
and NEXT_PUBLIC_BOOK_SLUG
to your .env.local
and .env.production
if these are the two tiers you are selling with the site.
To load development data from the rails api, make sure you rails db is set up and run yarn build:data:dev
. You will need to create a local BUNDLE_BUDDY_TOKEN
(See below for details).
Get your BUNDLE_BUDDY_TOKEN
in your env.development
. This can be generated by logging into your rails console with rails c
and:
user = User.find_by_email('[email protected]')
user.access_tokens.create
Make sure bundle buddy has the :bundler
role.
user = User.find_by_email('[email protected]')
user.roles.map(&:name)
# => ["user", "bundler"]
# if bundler isnt in that array:
user.add_role :bundler
To log in, you need to have a purchase associated with the log in email.
Once you have a purchase, head over to the /login
page and enter your email. If you are running local development, the log in link will be printed to the console of the egghead-rails
server.
If you are in production, you should receive an email with a log in link.
rake staging:update_local_dev_database
in your egghead-rails
directory to get the latest DB.
The DB updater needs github creds that go in ~/.netrc
:
machine api.github.com
login USERNAME
password SECRET
An oauth application will need to be created in the egghead database. It's better to create an Oauth Application (here's the link) on production and copy the values to local dev so you dont get conflicting variables later on.
If one doesn't exist for the site already, then we will have to create one in the production and development database.
In the rails console:
application = Doorkeeper::Application.create(
name: "My Product",
redirect_uri: "https://my-product.com/redirect",
confidential: false,
internal_application: true,
site_url: "https://my-product.com",
statement_descriptor: "My Product"
)
site_tenant = SiteTenant.create(name: 'my_product', application: application)
application.uid # this value should be placed in NEXT_PUBLIC_CLIENT_ID
site_tenant.name # this value should be placed in NEXT_PUBLIC_SITE_NAME
When creating the oauth application in production you will want to set the image for the application.
There are a couple of things you need to do to require login for a page.
The first thing is import up useRequireLogin
.
import useLoginRequired from 'hooks/use-login-required'
This hook will return a boolean
value. This value lets you know if the hook is still verifying that the user has access to the page. So if the hook is still verifying, we need to return null
from our component to avoid a potential flash of content before the redirect.
const SomeComponent = () => {
const isVerifying = useLoginRequired()
if (isVerifying) {
return null
}
return <></>
}
We use Stripe to capture purchases. There are TODO
s in src/components/commerce
to adjust the code based on what kinds of packages we are selling.
You will need to get a Stripe public test token to make purchases in development. This key will be set in the NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
env variable.
To test purchases on local development you will need:
- egghead-rails running locally
- stripe-cli installed
- a test stripe secret key
- a bundle set up
- a
SiteTenant
and Oauth Application set up
If you have all of these things, then you can start egghead-rails like so:
cd ~/path/to/egghead-rails
yarn develop
Then you can start the stripe cli:
stripe listen --forward-to "http://app.egghead.af:5000/stripe_events.json?site_name=my_product_site_name&api_key=stripe_webhook_api_key" --api-key "sk_test_your-stripe-secret-token"
You should notice you will need to replace the values for my_product_site_name
, stripe_webhook_api_key
and sk_test_your-stripe-secret-token
.
You should already have the site_name
for the product. To get the stripe_webhook_api_key
, you can run this in the rails console
.
site_tenant = SiteTenant.find_by(name: 'my_product_site_name')
stripe_webhook_api_key = site_tenant.stripe_webhook_api_key
stripe_secret_key = site_tenant.stripe_secret_key # this will be set if the product has already been set up
stripe_public_key = site_tenant.stripe_publishable_key # this will be set if the product has already been set up