Skip to content

Instantly share code, notes, and snippets.

@sjb9774
Last active July 24, 2023 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sjb9774/5d70e7c56a33b1529cfa9fce1bccf101 to your computer and use it in GitHub Desktop.
Save sjb9774/5d70e7c56a33b1529cfa9fce1bccf101 to your computer and use it in GitHub Desktop.
Used with the Shopify Node App Template to get the access token stored in the installation session
// run from within app web/ directory, presumes the sqlite db file is named "database.sqlite" (default for template)
const DB_FILE_PATH = './database.sqlite';
const getAccessToken = async () => {
return new Promise((resolve, reject) => {
import('sqlite3').then((sqlite) => {
const db = new sqlite.default.Database(DB_FILE_PATH);
db.serialize(() => {
db.get('SELECT accessToken FROM shopify_sessions LIMIT 1;', [], (err, { accessToken }) => {
return resolve(accessToken);
});
});
});
});
}
console.log(await getAccessToken());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment