Skip to content
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

Master2 #65

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b818eb6
added authenticator
BabylonCoding Nov 20, 2024
65e4b81
added authenticator
BabylonCoding Nov 20, 2024
c95d47f
added per-user data isolation
BabylonCoding Nov 21, 2024
6899f6d
adding signin
BabylonCoding Dec 10, 2024
8bce18c
try to ad layout
BabylonCoding Dec 11, 2024
02b9a75
corrections
BabylonCoding Dec 11, 2024
bce8bf5
spotlight removed
BabylonCoding Dec 11, 2024
d78eaf5
spotlight removed
BabylonCoding Dec 11, 2024
6b3355e
corrections
BabylonCoding Dec 11, 2024
58c9846
profile work started
BabylonCoding Dec 14, 2024
45290ff
profile work started
BabylonCoding Dec 14, 2024
5d03701
profile work started
BabylonCoding Dec 14, 2024
6be0a3a
profile work started
BabylonCoding Dec 14, 2024
07d3bb4
profile work started
BabylonCoding Dec 15, 2024
76822ce
profile work started
BabylonCoding Dec 15, 2024
fc3016f
profile work started
BabylonCoding Dec 15, 2024
1c93df0
profile work started
BabylonCoding Dec 15, 2024
e6f3e4c
profile work started
BabylonCoding Dec 15, 2024
33b798a
add profile com
BabylonCoding Dec 18, 2024
baeea0f
add profile com
BabylonCoding Dec 18, 2024
d7bc47d
Profile table added
BabylonCoding Dec 18, 2024
edde845
Profile table added
BabylonCoding Dec 18, 2024
65baeeb
Profile table added
BabylonCoding Dec 19, 2024
cc4603c
Profile table added
BabylonCoding Dec 20, 2024
b2133db
Profile table added
BabylonCoding Dec 20, 2024
c488b58
Profile table added
BabylonCoding Dec 20, 2024
c546a2f
Profile table added
BabylonCoding Dec 20, 2024
1e87ea6
Profile table added
BabylonCoding Dec 20, 2024
4c344ea
Profile table added
BabylonCoding Dec 20, 2024
59c9a1b
Profile table added
BabylonCoding Dec 20, 2024
8ef1f7b
Profile table added
BabylonCoding Dec 20, 2024
7949d06
Profile table added
BabylonCoding Dec 20, 2024
a2b0357
Profile table added
BabylonCoding Dec 20, 2024
8c45292
Profile table added
BabylonCoding Dec 20, 2024
85ec4dc
Profile edit form
BabylonCoding Dec 22, 2024
da77cc5
Profile fill form
BabylonCoding Dec 22, 2024
0ca3c56
Profile fill form
BabylonCoding Dec 22, 2024
8bc9cce
Profile fill form
BabylonCoding Dec 22, 2024
4598781
Profile fill form
BabylonCoding Dec 22, 2024
3fa1b3d
add profile com
BabylonCoding Dec 22, 2024
f023591
add profile com
BabylonCoding Dec 23, 2024
a1cd8b1
add profile com
BabylonCoding Dec 23, 2024
a4786dd
add profile com
BabylonCoding Dec 23, 2024
00b56ed
add profile com
BabylonCoding Dec 23, 2024
16b973a
add profile com
BabylonCoding Dec 23, 2024
c14df7f
add profile com
BabylonCoding Dec 23, 2024
364a5a6
add profile com
BabylonCoding Dec 23, 2024
dcc2461
add upploading form
BabylonCoding Dec 26, 2024
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
11 changes: 11 additions & 0 deletions amplify-backup/auth/resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineAuth } from "@aws-amplify/backend";

/**
* Define and configure your auth resource
* @see https://docs.amplify.aws/gen2/build-a-backend/auth
*/
export const auth = defineAuth({
loginWith: {
email: true,
},
});
8 changes: 8 additions & 0 deletions amplify-backup/backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineBackend } from '@aws-amplify/backend';
import { auth } from './auth/resource.js';
import { data } from './data/resource.js';

defineBackend({
auth,
data,
});
66 changes: 66 additions & 0 deletions amplify-backup/data/resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { type ClientSchema, a, defineData } from "@aws-amplify/backend";

/*== STEP 1 ===============================================================
The section below creates a Todo database table with a "content" field. Try
adding a new "isDone" field as a boolean. The authorization rule below
specifies that any user authenticated via an API key can "create", "read",
"update", and "delete" any "Todo" records.
=========================================================================*/
const schema = a.schema({
Todo: a
.model({
content: a.string(),
// isDone: a.boolean(),
}),
Profile: a
.model({
name: a.string(),
tel: a.string(),
address1: a.string(),
address2: a.string(),
city: a.string(),
country: a.string(),
})
.authorization((allow) => [allow.owner()]),
});

export type Schema = ClientSchema<typeof schema>;

export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: "userPool",
apiKeyAuthorizationMode: {
expiresInDays: 30,
},
},
});

/*== STEP 2 ===============================================================
Go to your frontend source code. From your client-side code, generate a
Data client to make CRUDL requests to your table. (THIS SNIPPET WILL ONLY
WORK IN THE FRONTEND CODE FILE.)

Using JavaScript or Next.js React Server Components, Middleware, Server
Actions or Pages Router? Review how to generate Data clients for those use
cases: https://docs.amplify.aws/gen2/build-a-backend/data/connect-to-API/
=========================================================================*/

/*
"use client"
import { generateClient } from "aws-amplify/data";
import type { Schema } from "@/amplify/data/resource";

const client = generateClient<Schema>() // use this Data client for CRUDL requests
*/

/*== STEP 3 ===============================================================
Fetch records from the database and use them in your frontend component.
(THIS SNIPPET WILL ONLY WORK IN THE FRONTEND CODE FILE.)
=========================================================================*/

/* For example, in a React component, you can use this snippet in your
function's RETURN statement */
// const { data: todos } = await client.models.Todo.list()

// return <ul>{todos.map(todo => <li key={todo.id}>{todo.content}</li>)}</ul>
3 changes: 3 additions & 0 deletions amplify-backup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
17 changes: 17 additions & 0 deletions amplify-backup/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2022",
"module": "es2022",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"paths": {
"$amplify/*": [
"../.amplify/generated/*"
]
}
}
}
16 changes: 14 additions & 2 deletions amplify/data/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@ const schema = a.schema({
Todo: a
.model({
content: a.string(),
// isDone: a.boolean(),
})
.authorization((allow) => [allow.publicApiKey()]),
.authorization((allow) => [allow.owner()]),
Profile: a
.model({
name: a.string(),
tel: a.string(),
address1: a.string(),
address2: a.string(),
city: a.string(),
country: a.string(),
})
.authorization((allow) => [allow.owner()]),

});

export type Schema = ClientSchema<typeof schema>;

export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: "apiKey",
defaultAuthorizationMode: "userPool",
apiKeyAuthorizationMode: {
expiresInDays: 30,
},
Expand Down
72 changes: 72 additions & 0 deletions app/Startpage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"use client";

import { useState, useEffect } from "react";
import { generateClient } from "aws-amplify/data";
import type { Schema } from "@/amplify/data/resource";
import "./app.css";
import { Amplify } from "aws-amplify";
import outputs from "@/amplify_outputs.json";
import "@aws-amplify/ui-react/styles.css";
import { Authenticator } from '@aws-amplify/ui-react';
import React from 'react';
import { useAuthenticator } from '@aws-amplify/ui-react';
Amplify.configure(outputs);

const client = generateClient<Schema>();





export const Startpage = () => {
const { user, signOut } = useAuthenticator();

const [todos, setTodos] = useState<Array<Schema["Todo"]["type"]>>([]);

function listTodos() {
client.models.Todo.observeQuery().subscribe({
next: (data) => setTodos([...data.items]),
});
}

useEffect(() => {
listTodos();
}, []);

function createTodo() {
client.models.Todo.create({
content: window.prompt("Todo content"),
});
}

function deleteTodo(id: string) {
client.models.Todo.delete({ id })
}
return (

<main>
<h1>{user?.username}</h1>
<h1>{user?.signInDetails?.loginId}'s todos</h1>
<h1>My todos</h1>
<button onClick={signOut}>Sign out</button>
<button onClick={createTodo}>+ new</button>
<ul>

{
todos.map((todo) => (
<li
onClick={() => deleteTodo(todo.id)}
key={todo.id}>{todo.content}</li>
))}
</ul>
<div>
🥳 App successfully hosted. Try creating a new todo.
<br />
<a href="https://docs.amplify.aws/nextjs/start/quickstart/nextjs-app-router-client-components/">
Review next steps of this tutorial.
</a>
</div>
</main>

);
}
68 changes: 3 additions & 65 deletions app/app.css
Original file line number Diff line number Diff line change
@@ -1,65 +1,3 @@
body {
margin: 0;
background: linear-gradient(180deg, rgb(117, 81, 194), rgb(255, 255, 255));
display: flex;
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
height: 100vh;
width: 100vw;
justify-content: center;
align-items: center;
}

main {
display: flex;
flex-direction: column;
align-items: stretch;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
color: white;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

ul {
padding-inline-start: 0;
margin-block-start: 0;
margin-block-end: 0;
list-style-type: none;
display: flex;
flex-direction: column;
margin: 8px 0;
border: 1px solid black;
gap: 1px;
background-color: black;
border-radius: 8px;
overflow: auto;
}

li {
background-color: white;
padding: 8px;
}

li:hover {
background: #dadbf9;
}

a {
font-weight: 800;
text-decoration: none;
}
@tailwind base;
@tailwind components;
@tailwind utilities;
Loading