Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Данные для ВК в переменных окружения #49

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
DATABASE_URL=postgresql://postgres@postgres:5432
REDIS_URL=redis://redis:6379/1
VK_AUTH_REDIRECT_URL=http://localhost/auth/vkontakte/callback
VK_APP_ID=
vzalygin marked this conversation as resolved.
Show resolved Hide resolved
64 changes: 32 additions & 32 deletions app/javascript/controllers/vkid_controller.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static values ={
pkce: Object
}
connect() {
const VKID = window.VKIDSDK;
const data = this.pkceValue
const challenge = data.challenge
const state = data.state
// Fetch the JSON data from 'auth/challenge'
// Set VKID config with fetched data
VKID.Config.init({
app: 51989509, // Идентификатор приложения.
redirectUrl: 'http://localhost:3000/auth/vkontakte/callback', // Адрес для перехода после авторизации.
codeChallenge: challenge,
state: state,
//scope: "friends wall"
});
// Создание экземпляра кнопки.
const oneTap = new VKID.OneTap();
// Получение контейнера из разметки.
const container = document.getElementById('VkIdSdkOneTap');
// Проверка наличия кнопки в разметке.
if (container) {
// Отрисовка кнопки в контейнере с именем приложения APP_NAME, светлой темой и на русском языке.
const res = oneTap.render({ container: container, scheme: VKID.Scheme.LIGHT, lang: VKID.Languages.RUS })
}
}};
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static values ={
pkce: Object
}

connect() {
const VKID = window.VKIDSDK;
const data = this.pkceValue;
const challenge = data.challenge;
const state = data.state;
// Fetch the JSON data from 'auth/challenge'
// Set VKID config with fetched data
VKID.Config.init({
app: window.VK_APP_ID, // Идентификатор приложения.
redirectUrl: window.VK_AUTH_REDIRECT_URL, // Адрес для перехода после авторизации.
codeChallenge: challenge,
state: state,
//scope: "friends wall"
});
// Создание экземпляра кнопки.
const oneTap = new VKID.OneTap();
// Получение контейнера из разметки.
const container = document.getElementById('VkIdSdkOneTap');
// Проверка наличия кнопки в разметке.
if (container) {
// Отрисовка кнопки в контейнере с именем приложения APP_NAME, светлой темой и на русском языке.
const res = oneTap.render({ container: container, scheme: VKID.Scheme.LIGHT, lang: VKID.Languages.RUS })
}
}
};
48 changes: 26 additions & 22 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Where my likes</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<script src="https://unpkg.com/@vkid/sdk@<3.0.0/dist-sdk/umd/index.js"></script>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
<%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>
</head>
<body>
<%= render partial: "partial_content/navbar"%>
<main class="raleway">
<%= yield %>
</main>
<%= render partial: "partial_content/footer"%>
</body>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Where my likes</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<script src="https://unpkg.com/@vkid/sdk@<3.0.0/dist-sdk/umd/index.js"></script>
<script>
window.VK_AUTH_REDIRECT_URL = "<%= Rails.VK_AUTH_REDIRECT_URL %>"
window.VK_APP_ID = "<%= Rails.VK_APP_ID %>"
</script>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
Comment on lines +10 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Имхо, я бы не скрипт ставил, а мета-теги, но не принципиально)

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
<%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>
</head>
<body>
<%= render partial: "partial_content/navbar"%>
<main class="raleway">
<%= yield %>
</main>
<%= render partial: "partial_content/footer"%>
</body>
Loading