Auth0 related changes

This commit is contained in:
Markus Thielen 2023-05-16 12:25:44 +02:00
parent 89ae48138e
commit 8bb10266b0
6 changed files with 109 additions and 92 deletions

View File

@ -1,33 +1,62 @@
[resolvers.createTask] [resolvers.getUser]
operation_name = "createTask" operation_name = "getUser"
[resolvers.createTask.resolver] [resolvers.getUser.resolver]
command_type = "SQLSelect"
[resolvers.getUser.resolver.command]
table = "User"
columns = []
modify_values = []
nested_modify_tables = []
aggregate_result = true
[[resolvers.getUser.resolver.command.where_clauses]]
table = "User"
column = "username"
condition_str = "= '$username'"
index = ""
[resolvers.updateList]
operation_name = "updateList"
[resolvers.updateList.resolver]
command_type = "SQLUpdate"
[resolvers.updateList.resolver.command]
table = "List"
columns = []
nested_modify_tables = []
aggregate_result = true
[[resolvers.updateList.resolver.command.modify_values]]
column = "title"
value = "'$title'"
[[resolvers.updateList.resolver.command.where_clauses]]
table = "List"
column = "id"
condition_str = "= '$id'"
index = ""
[resolvers.createList]
operation_name = "createList"
[resolvers.createList.resolver]
command_type = "SQLInsert" command_type = "SQLInsert"
[resolvers.createTask.resolver.command] [resolvers.createList.resolver.command]
table = "Task" table = "List"
columns = [] columns = []
nested_modify_tables = [] nested_modify_tables = []
where_clauses = [] where_clauses = []
aggregate_result = true aggregate_result = true
[[resolvers.createTask.resolver.command.modify_values]] [[resolvers.createList.resolver.command.modify_values]]
column = "title" column = "title"
value = "'$title'" value = "'$title'"
[[resolvers.createTask.resolver.command.modify_values]] [[resolvers.createList.resolver.command.modify_values]]
column = "description"
value = "'$description'"
[[resolvers.createTask.resolver.command.modify_values]]
column = "completed"
value = "'$completed'"
[[resolvers.createTask.resolver.command.modify_values]]
column = "list_id"
value = "'$list.$id'"
[[resolvers.createTask.resolver.command.modify_values]]
column = "user_username" column = "user_username"
value = "'$user.$username'" value = "'$user.$username'"
@ -71,6 +100,39 @@ column = "id"
condition_str = "= '$id'" condition_str = "= '$id'"
index = "" index = ""
[resolvers.createTask]
operation_name = "createTask"
[resolvers.createTask.resolver]
command_type = "SQLInsert"
[resolvers.createTask.resolver.command]
table = "Task"
columns = []
nested_modify_tables = []
where_clauses = []
aggregate_result = true
[[resolvers.createTask.resolver.command.modify_values]]
column = "title"
value = "'$title'"
[[resolvers.createTask.resolver.command.modify_values]]
column = "description"
value = "'$description'"
[[resolvers.createTask.resolver.command.modify_values]]
column = "completed"
value = "'$completed'"
[[resolvers.createTask.resolver.command.modify_values]]
column = "list_id"
value = "'$list.$id'"
[[resolvers.createTask.resolver.command.modify_values]]
column = "user_username"
value = "'$user.$username'"
[resolvers.deleteList] [resolvers.deleteList]
operation_name = "deleteList" operation_name = "deleteList"
@ -90,27 +152,6 @@ column = "id"
condition_str = "= '$id'" condition_str = "= '$id'"
index = "" index = ""
[resolvers.createList]
operation_name = "createList"
[resolvers.createList.resolver]
command_type = "SQLInsert"
[resolvers.createList.resolver.command]
table = "List"
columns = []
nested_modify_tables = []
where_clauses = []
aggregate_result = true
[[resolvers.createList.resolver.command.modify_values]]
column = "title"
value = "'$title'"
[[resolvers.createList.resolver.command.modify_values]]
column = "user_username"
value = "'$user.$username'"
[resolvers.updateTask] [resolvers.updateTask]
operation_name = "updateTask" operation_name = "updateTask"
@ -144,44 +185,3 @@ table = "Task"
column = "id" column = "id"
condition_str = "= '$id'" condition_str = "= '$id'"
index = "" index = ""
[resolvers.getUser]
operation_name = "getUser"
[resolvers.getUser.resolver]
command_type = "SQLSelect"
[resolvers.getUser.resolver.command]
table = "User"
columns = []
modify_values = []
nested_modify_tables = []
aggregate_result = true
[[resolvers.getUser.resolver.command.where_clauses]]
table = "User"
column = "username"
condition_str = "= '$username'"
index = ""
[resolvers.updateList]
operation_name = "updateList"
[resolvers.updateList.resolver]
command_type = "SQLUpdate"
[resolvers.updateList.resolver.command]
table = "List"
columns = []
nested_modify_tables = []
aggregate_result = true
[[resolvers.updateList.resolver.command.modify_values]]
column = "title"
value = "'$title'"
[[resolvers.updateList.resolver.command.where_clauses]]
table = "List"
column = "id"
condition_str = "= '$id'"
index = ""

View File

@ -46,7 +46,7 @@ function dismissError() {
</li> </li>
</ul> </ul>
<ul class="navbar-nav mb-2 mb-lg-0"> <ul class="navbar-nav mb-2 mb-lg-0">
<li class="navbar-text">Hello, {{ store.session.username }}!</li> <li class="navbar-text">Hello, {{ store.userDisplayName }}!</li>
<li class="nav-item ms-2"> <li class="nav-item ms-2">
<button class="nav-link btn btn-sm btn-secondary" @click="logOut()">Logout</button> <button class="nav-link btn btn-sm btn-secondary" @click="logOut()">Logout</button>
</li> </li>

View File

@ -78,7 +78,7 @@ export default {
createList( createList(
title: "${list.title}" title: "${list.title}"
user: { user: {
username: "${store.session.username}" username: "${store.userId}"
} }
) { ) {
id id

View File

@ -128,7 +128,7 @@ export default {
id: "${task.list.id}" id: "${task.list.id}"
}, },
user: { user: {
username: "${store.session.username}" username: "${store.userId}"
} }
) { ) {
id id

View File

@ -12,7 +12,7 @@ import { store} from "../store";
<template> <template>
<div class="greetings"> <div class="greetings">
<h1 class="primary">Welcome, {{ store.userName }}!</h1> <h1 class="primary">Welcome, {{ store.userDisplayName }}!</h1>
<h3> <h3>
To basebox' ToDo Sample app. To basebox' ToDo Sample app.
</h3> </h3>

View File

@ -9,8 +9,11 @@ import {gqlQuery} from "./util/net";
export const store = reactive({ export const store = reactive({
/** Username of the currently logged-in user */ /** User display name of the currently logged-in user */
userName: "stranger", userDisplayName: "stranger",
/* Unique user id of the currently logged in user */
userId: "",
/** base URL of basebox broker host */ /** base URL of basebox broker host */
baseboxHost: import.meta.env.BASEBOX_HOST || "http://127.0.0.1:8080", baseboxHost: import.meta.env.BASEBOX_HOST || "http://127.0.0.1:8080",
@ -72,7 +75,21 @@ export async function storeInit(session) {
/* save user session in the store */ /* save user session in the store */
store.session = { ...session }; store.session = { ...session };
store.userName = session.first_name ? session.first_name : session.username;
/* The information in the session object depends on the OpenID Connect provider.
* The following fields are always present:
*
* `token` - basebox session token
* `subject` - unique user id (not a username, rather a number or UUID)
* `id_token_claims` - all fields found in the ID token.
*
* Since we assume Auth0 being the Open ID Connect provider, we use `id_token_claims.nickname`
* as the user name we display in the UI.
*/
store.userDisplayName = session.id_token_claims.nickname;
/* The unique user ID is the 'sub' field from the ID token. */
store.userId = session.subject;
/* Create user and default list. /* Create user and default list.
* We cannot run these requests in parallel, since the user record must exist in the database * We cannot run these requests in parallel, since the user record must exist in the database
@ -82,8 +99,8 @@ export async function storeInit(session) {
console.info("NOTE: If next request fails, it is probably because the user already exists. In this case, the error is ignored."); console.info("NOTE: If next request fails, it is probably because the user already exists. In this case, the error is ignored.");
await gqlQuery(`mutation { await gqlQuery(`mutation {
createUser( createUser(
username: "${session.username}", username: "${store.userId}",
name: "${session.first_name} ${session.last_name}" name: "${store.userDisplayName}"
) { ) {
username username
} }
@ -101,7 +118,7 @@ export async function storeInit(session) {
/* Load user info, lists and todos. */ /* Load user info, lists and todos. */
gqlQuery(`query { gqlQuery(`query {
getUser(username: "${store.session.username}") { getUser(username: "${store.userId}") {
name name
lists { lists {
id id
@ -125,7 +142,7 @@ export async function storeInit(session) {
gqlQuery(`mutation { gqlQuery(`mutation {
createList( createList(
title: "Default", title: "Default",
user: { username: "${store.session.username}" } user: { username: "${store.userId}" }
) { ) {
title title
} }