Skip to content

add svelte Authenticator #6625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Amplify UI is an open-source UI library with cloud-connected components that are
| [@aws-amplify/ui-react](https://www.npmjs.com/package/@aws-amplify/ui-react) | ![](https://img.shields.io/npm/dw/@aws-amplify/ui-react?label=Download&logo=Amplify&style=flat) | ![](https://img.shields.io/npm/v/@aws-amplify/ui-react/latest) |
| [@aws-amplify/ui-vue](https://www.npmjs.com/package/@aws-amplify/ui-vue) | ![](https://img.shields.io/npm/dw/@aws-amplify/ui-vue?label=Download&logo=Amplify) | ![](https://img.shields.io/npm/v/@aws-amplify/ui-vue/latest?style=flat) |
| [@aws-amplify/ui-angular](https://www.npmjs.com/package/@aws-amplify/ui-angular) | ![](https://img.shields.io/npm/dw/@aws-amplify/ui-angular?label=Download&logo=Amplify) | ![](https://img.shields.io/npm/v/@aws-amplify/ui-angular/latest) |
| [@aws-amplify/ui-svelte](https://www.npmjs.com/package/@aws-amplify/ui-svelte) | ![](https://img.shields.io/npm/dw/@aws-amplify/ui-svelte?label=Download&logo=Amplify) | ![](https://img.shields.io/npm/v/@aws-amplify/ui-svelte/latest) |

## Documentation

Expand All @@ -36,9 +37,9 @@ Amplify UI is an open-source UI library with cloud-connected components that are

## Component Matrix

| **Connected Components** | **React** | **React Native** | **Angular** | **Vue** |
| :----------------------- | :-------: | :--------------: | :---------: | :-----: |
| Authenticator | ✅ | ✅ | ✅ | ✅ |
| **Connected Components** | **React** | **React Native** | **Angular** | **Vue** | **Svelte** |
| :----------------------- | :-------: | :--------------: | :---------: | :-----: | :--------: |
| Authenticator | ✅ | ✅ | ✅ | ✅ | ✅ |
| InAppMessagingDisplay | ✅ | ✅ | | |
| MapView/LocationSearch | ✅ | | | |
| Account Settings | ✅ | | | |
Expand Down
76 changes: 76 additions & 0 deletions examples/ui/components/authenticator/svelte/App.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<script lang="ts">
import { Authenticator } from '@aws-amplify/ui-svelte';
import { Amplify } from 'aws-amplify';
import awsExports from './aws-exports';

Amplify.configure(awsExports);

// Check for URL parameters to enable different features
const params = new URLSearchParams(window.location.search);
const hideSignUp = params.get('hideSignUp') === 'true';
const socialProviders = params.get('socialProviders')?.split(',') || [];
</script>

<main>
<h1>Amplify Svelte Authenticator</h1>

<Authenticator
{hideSignUp}
socialProviders={socialProviders.length > 0 ? socialProviders : undefined}
let:authStatus
let:user
let:signOut
>
<div class="authenticated-content">
<h2>Hello {user?.username}</h2>
<p>You are signed in!</p>
<div id="auth-status">Sign out</div>
<div id="custom-authenticated-content">Custom authenticated content</div>

<button on:click={signOut} class="sign-out-button">
Sign out
</button>
</div>
</Authenticator>
</main>

<style>
main {
max-width: 600px;
margin: 0 auto;
padding: 2rem;
}

h1 {
text-align: center;
margin-bottom: 2rem;
}

.authenticated-content {
text-align: center;
padding: 2rem;
background-color: #f5f5f5;
border-radius: 8px;
}

.sign-out-button {
margin-top: 1rem;
padding: 0.5rem 1rem;
background-color: #ff3e00;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}

.sign-out-button:hover {
background-color: #ff5a00;
}

#custom-authenticated-content {
margin-top: 1rem;
padding: 1rem;
background-color: #e0e0e0;
border-radius: 4px;
}
</style>
33 changes: 33 additions & 0 deletions examples/ui/components/authenticator/svelte/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: #213547;
background-color: #ffffff;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}

body {
margin: 0;
min-width: 320px;
min-height: 100vh;
}

#app {
margin: 0 auto;
padding: 2rem;
}

@media (prefers-color-scheme: dark) {
:root {
color: #f6f6f6;
background-color: #2f2f2f;
}
}
13 changes: 13 additions & 0 deletions examples/ui/components/authenticator/svelte/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Amplify Svelte Authenticator</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/main.ts"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions examples/ui/components/authenticator/svelte/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import './app.css';
import App from './App.svelte';

const app = new App({
target: document.getElementById('app')!,
});

export default app;
21 changes: 21 additions & 0 deletions examples/ui/components/authenticator/svelte/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@aws-amplify/ui-svelte-authenticator-example",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"svelte": "^4.2.7",
"typescript": "^5.2.2",
"vite": "^5.0.8"
},
"dependencies": {
"@aws-amplify/ui-svelte": "workspace:*",
"aws-amplify": "^6.14.2"
}
}
18 changes: 18 additions & 0 deletions examples/ui/components/authenticator/svelte/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"resolveJsonModule": true,
"allowJs": true,
"checkJs": true,
"isolatedModules": true,
"moduleResolution": "bundler",
"paths": {
"@environments/*": ["../../../../environments/*"]
}
},
"include": ["**/*.ts", "**/*.js", "**/*.svelte"],
"references": [{ "path": "./tsconfig.node.json" }]
}
11 changes: 11 additions & 0 deletions examples/ui/components/authenticator/svelte/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts"]
}
16 changes: 16 additions & 0 deletions examples/ui/components/authenticator/svelte/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import path from 'path';

export default defineConfig({
plugins: [svelte()],
resolve: {
alias: {
'@environments': path.resolve(__dirname, '../../../../environments'),
},
},
server: {
port: 3000,
open: true,
},
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"test-utils": "yarn workspace @aws-amplify/ui-test-utils",
"ui": "yarn workspace @aws-amplify/ui",
"vue": "yarn workspace @aws-amplify/ui-vue",
"svelte": "yarn workspace @aws-amplify/ui-svelte",
"angular-example": "yarn workspace @aws-amplify/ui-angular-example",
"docs": "yarn workspace @aws-amplify/ui-docs",
"next-example": "yarn workspace @aws-amplify/ui-next-pages-router-example",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Feature: Authenticator Component for Svelte

Amplify UI Authenticator provides a complete authentication flow for Svelte applications.

Background:
Given I'm running the example "ui/components/authenticator/svelte"

@svelte @react @vue @angular
Scenario: Sign in with valid credentials
When I type my "username" with status "CONFIRMED"
And I type my password
And I click the "Sign in" button
Then I see "Sign out"

@svelte @react @vue @angular
Scenario: Sign in with wrong credentials
When I type my "username" with status "CONFIRMED"
And I type an invalid password
And I click the "Sign in" button
Then I see "Incorrect username or password"

@svelte @react @vue @angular
Scenario: Sign up a new user
Given I intercept '{ "headers": { "X-Amz-Target": "AWSCognitoIdentityProviderService.SignUp" } }' with fixture "sign-up-with-email"
When I click the "Create Account" tab
And I type a new "username"
And I type my password
And I confirm my password
And I type my "email" with value "test@example.com"
And I click the "Create Account" button
Then I see "Confirm Sign Up"

@svelte @react @vue @angular
Scenario: Confirm sign up
Given I intercept '{ "headers": { "X-Amz-Target": "AWSCognitoIdentityProviderService.ConfirmSignUp" } }' with fixture "confirm-sign-up-success"
And I'm at the "Confirm Sign Up" page
When I type a valid confirmation code
And I click the "Confirm" button
Then I see "Sign In"

@svelte @react @vue @angular
Scenario: Reset password
When I click the "Forgot your password?" button
Then I see "Reset your password"
When I type my "username" with status "CONFIRMED"
And I click the "Send Code" button
Then I see "Reset your password"

@svelte @react @vue @angular
Scenario: Force new password flow
When I type my "username" with status "FORCE_NEW_PASSWORD"
And I type my password
And I click the "Sign in" button
Then I see "Change Password"

@svelte @react @vue @angular
Scenario: Setup TOTP flow
When I type my "username" with status "TOTP_SETUP"
And I type my password
And I click the "Sign in" button
Then I see "Setup Two-Factor Authentication"

@svelte @react @vue @angular
Scenario: Sign in with federated provider
Given "google" login is enabled
Then I see the "Sign in with Google" button

@svelte @react @vue @angular
Scenario: Hide sign up
Given "hideSignUp" is enabled
Then I don't see "Create Account"

@svelte @react @vue @angular
Scenario: Custom slot content when authenticated
When I type my "username" with status "CONFIRMED"
And I type my password
And I click the "Sign in" button
Then I see "Hello testuser"
And I see custom authenticated content
46 changes: 46 additions & 0 deletions packages/svelte/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-env node */
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['import', 'svelte', '@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:svelte/recommended',
],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
extraFileExtensions: ['.svelte'],
},
env: {
browser: true,
es2017: true,
node: true,
},
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
},
},
],
ignorePatterns: ['dist', 'node_modules', '*.cjs'],
rules: {
'import/no-extraneous-dependencies': [
'error',
{
packageDir: ['.', '../..'],
},
],
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
28 changes: 28 additions & 0 deletions packages/svelte/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Dependencies
node_modules/

# Build output
dist/

# IDE
.vscode/
.idea/

# OS
.DS_Store
Thumbs.db

# Logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Test coverage
coverage/
.nyc_output/

# Temporary files
*.tmp
*.temp
.cache/
Loading