Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
feat: add mock auth plugin (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuhang Shi committed Jul 26, 2022
1 parent 63fb1b5 commit 740f649
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 2 deletions.
13 changes: 11 additions & 2 deletions apps/client-web/src/routes/accounts/sign-up.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,19 @@ export const SignUp: React.FC = () => {
const form = Form.useForm<UserCreateInput>({
mode: 'onBlur',
reValidateMode: 'onBlur',
yup: hasFederatedIdentity ? basicValidation : emailPasswordFormValidation,
defaultValues: initialValues
yup: hasFederatedIdentity ? basicValidation : emailPasswordFormValidation
})

// https://react-hook-form.com/api/useform/reset
React.useEffect(() => {
form.reset({
domain: initialValues.domain,
name: initialValues.name,
locale: initialValues.locale,
timezone: initialValues.timezone
})
}, [form, initialValues.domain, initialValues.name, initialValues.locale, initialValues.timezone])

// Email unactive tips
if (didShowConfirmationEmailTips) {
return <ConfirmationEmailTips email={form.getValues('email')!} />
Expand Down
1 change: 1 addition & 0 deletions apps/server-monolith/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Application < Rails::Application
'@mashcard/google-auth',
]
default_plugins.push '@pleisto/cloud' if ENV['MASHCARD_CLOUD_LICENSE'].present?
default_plugins.push '@mashcard/mock-auth' if ENV['RAILS_ENV'].in?(['development', 'test', 'cicd'])
default_plugins.each do |name|
plugin = Mashcard::Plugins.find(name)
raise "Plugin #{name} not found, but it should be enabled by default" if plugin.nil?
Expand Down
4 changes: 4 additions & 0 deletions apps/server-monolith/config/environments/cicd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@
# config.active_record.database_selector = { delay: 2.seconds }
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session

# https://edgeguides.rubyonrails.org/configuring.html#config-action-controller-default-protect-from-forgery
# Disable CSRF protection for development / test / cicd.
config.action_controller.default_protect_from_forgery = false
end
4 changes: 4 additions & 0 deletions apps/server-monolith/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

# https://edgeguides.rubyonrails.org/configuring.html#config-action-controller-default-protect-from-forgery
# Disable CSRF protection for development / test / cicd.
config.action_controller.default_protect_from_forgery = false
end
4 changes: 4 additions & 0 deletions apps/server-monolith/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@
config.log_level = ENV['ENABLED_DEBUG_LOG'].present? ? :debug : :warn
# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true

# https://edgeguides.rubyonrails.org/configuring.html#config-action-controller-default-protect-from-forgery
# Disable CSRF protection for development / test / cicd.
config.action_controller.default_protect_from_forgery = false
end
2 changes: 2 additions & 0 deletions plugins/mock_auth/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
inherit_gem:
rubocop-pleisto: rubocop.yml
4 changes: 4 additions & 0 deletions plugins/mock_auth/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

source 'https://rubygems.org'

4 changes: 4 additions & 0 deletions plugins/mock_auth/config/locales/en-US.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en-US:
accounts:
provider:
developer: 'Developer'
16 changes: 16 additions & 0 deletions plugins/mock_auth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "../../apps/client-web/src/public/json-schema/plugin.draft-2205.json",
"name": "@mashcard/mock-auth",
"license": "Apache-2.0",
"version": "0.1.0",
"sideEffects": false,
"engines": {
"mashcard": ">=0.1.0"
},
"extensionPoints": [
"server"
],
"scripts": {
"lint:rubocop": "BUNDLE_GEMFILE=../../apps/server-monolith/Gemfile bundle exec rubocop --parallel --config .rubocop.yml"
}
}
1 change: 1 addition & 0 deletions plugins/mock_auth/public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions plugins/mock_auth/server_plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

on :oauth_provider do
[:developer, { logo: asset_url('logo.svg') }]
end
6 changes: 6 additions & 0 deletions plugins/mock_auth/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../packages/dev-support/tsconfig.shared.json",
"compilerOptions": { "outDir": "dist" },
"include": ["**/*"],
"exclude": ["dist/**/*"]
}
6 changes: 6 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 740f649

Please sign in to comment.