auth send link common mutation

This commit is contained in:
tonyrewin 2022-09-17 21:23:30 +03:00
parent 90cfa1f128
commit 9f03a0e5cc
15 changed files with 61 additions and 117 deletions

View File

@ -1,9 +0,0 @@
git filter-branch --tag-name-filter 'cat' -f --tree-filter '
find . -type d -name binarydir | while read dir
do
find $dir -type f -name "*.ear" -o -name "*.war" -o -name "*.jar" -o -name "*.zip" -o -name "*.exe" | while read file
do
git rm -r -f --ignore-unmatch $file
done
done
' -- --all

View File

@ -8,8 +8,8 @@ import { useArticlesStore, loadSearchResults } from '../../stores/zine/articles'
import { useStore } from '@nanostores/solid' import { useStore } from '@nanostores/solid'
type Props = { type Props = {
query: string query?: string
results: Shout[] results?: Shout[]
} }
export const SearchPage = (props: Props) => { export const SearchPage = (props: Props) => {

View File

@ -1,23 +0,0 @@
import { ClientOptions, dedupExchange, fetchExchange, createClient, Exchange } from '@urql/core'
import { devtoolsExchange } from '@urql/devtools'
// FIXME actual value
const isDev = true
// export const baseUrl = 'https://.discours.io'
export const baseUrl = 'http://localhost:8000'
const exchanges: Exchange[] = [dedupExchange, fetchExchange]
if (isDev) {
exchanges.unshift(devtoolsExchange)
}
const options: ClientOptions = {
url: baseUrl,
maskTypename: true,
requestPolicy: 'cache-and-network',
exchanges
}
export const publicGraphQLClient = createClient(options)

View File

@ -2,7 +2,7 @@
import signIn from './query/auth-login' import signIn from './query/auth-login'
import signUp from './mutation/auth-register' import signUp from './mutation/auth-register'
import signOut from './mutation/auth-logout' import signOut from './mutation/auth-logout'
import checkEmail from './query/auth-check' import checkEmail from './query/auth-check-email'
import getSession from './mutation/my-session' import getSession from './mutation/my-session'
// articles // articles
import topOverall from './query/articles-top-rated' import topOverall from './query/articles-top-rated'

View File

@ -1,8 +1,8 @@
import { gql } from '@urql/core' import { gql } from '@urql/core'
export default gql` export default gql`
query ForgetQuery($email: String!) { query ConfirmEmailQuery($code: String!) {
forget(email: $email) { confirmEmail(code: $code) {
error error
} }
} }

View File

@ -1,9 +0,0 @@
import { gql } from '@urql/core'
export default gql`
query ResendQuery($email: String!) {
resend(email: $email) {
error
}
}
`

View File

@ -1,8 +1,8 @@
import { gql } from '@urql/core' import { gql } from '@urql/core'
export default gql` export default gql`
query ResetQuery($code: String!) { query SendLinkQuery($email: String!) {
reset(code: $code) { sendLink(email: $email) {
error error
} }
} }

View File

@ -4,8 +4,8 @@ import { devtoolsExchange } from '@urql/devtools'
// FIXME actual value // FIXME actual value
const isDev = true const isDev = true
export const baseUrl = 'https://newapi.discours.io' //export const baseUrl = 'https://newapi.discours.io'
//export const baseUrl = 'http://localhost:8000' export const baseUrl = 'http://localhost:8000'
const exchanges: Exchange[] = [dedupExchange, fetchExchange] const exchanges: Exchange[] = [dedupExchange, fetchExchange]

View File

@ -1,7 +1,7 @@
import { gql } from '@urql/core' import { gql } from '@urql/core'
export default gql` export default gql`
query ReactionsByShoutQuery($limit: String!, $limit: Int!, $offset: Int!) { query ReactionsByShoutQuery($slug: String!, $limit: String!, $limit: Int!, $offset: Int!) {
reactionsByShout(slug: $slug, limit: $limit, offset: $offset) { reactionsByShout(slug: $slug, limit: $limit, offset: $offset) {
id id
body body

View File

@ -5,17 +5,13 @@ import { Header } from '../components/Nav/Header'
import { Footer } from '../components/Discours/Footer' import { Footer } from '../components/Discours/Footer'
import { ServerRouterProvider } from '../components/providers/ServerRouterProvider' import { ServerRouterProvider } from '../components/providers/ServerRouterProvider'
import { t } from '../utils/intl' import { t } from '../utils/intl'
import { locale as langstore } from '../stores/ui'
import { useStore } from '@nanostores/solid'
const { pathname, search } = Astro.url const { pathname, search } = Astro.url
const lang = Astro.url.searchParams['lang']
// FIXME always returns ru
const locale = useStore(langstore)
--- ---
<ServerRouterProvider href={pathname + search}> <ServerRouterProvider href={pathname + search}>
<html lang={locale() || 'en'}> <html lang={lang || 'en'}>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />

View File

@ -1,4 +1,4 @@
import { atom, action } from 'nanostores' import { atom } from 'nanostores'
import type { AuthResult } from '../graphql/types.gen' import type { AuthResult } from '../graphql/types.gen'
import { getLogger } from '../utils/logger' import { getLogger } from '../utils/logger'
import { resetToken, setToken } from '../graphql/privateGraphQLClient' import { resetToken, setToken } from '../graphql/privateGraphQLClient'
@ -9,14 +9,14 @@ const log = getLogger('auth-store')
export const session = atom<AuthResult>() export const session = atom<AuthResult>()
export const signIn = async (params) => { export const signIn = async (params) => {
const s = await apiClient.signIn(params) const s = await apiClient.authLogin(params)
session.set(s) session.set(s)
setToken(s.token) setToken(s.token)
log.debug('signed in') log.debug('signed in')
} }
export const signUp = async (params) => { export const signUp = async (params) => {
const s = await apiClient.signUp(params) const s = await apiClient.authRegiser(params)
session.set(s) session.set(s)
setToken(s.token) setToken(s.token)
log.debug('signed up') log.debug('signed up')
@ -31,22 +31,18 @@ export const signOut = () => {
export const emailChecks = atom<{ [email: string]: boolean }>({}) export const emailChecks = atom<{ [email: string]: boolean }>({})
export const signCheck = async (params) => { export const signCheck = async (params) => {
emailChecks.set(await apiClient.signCheck(params)) emailChecks.set(await apiClient.authCheckEmail(params))
} }
export const resetCode = atom<string>() export const resetCode = atom<string>()
export const signReset = async (params) => { export const signSendLink = async (params) => {
await apiClient.signReset(params) // { email } await apiClient.authSendLink(params) // { email }
resetToken() resetToken()
} }
export const signResend = async (params) => { export const signConfirm = async (params) => {
await apiClient.signResend(params) // { email } const auth = await apiClient.authConfirmCode(params) // { code }
}
export const signResetConfirm = async (params) => {
const auth = await apiClient.signResetConfirm(params) // { code }
setToken(auth.token) setToken(auth.token)
session.set(auth) session.set(auth)
} }

View File

@ -105,7 +105,6 @@ type InitialState = {
} }
export const useTopicsStore = ({ topics, randomTopics }: InitialState = {}) => { export const useTopicsStore = ({ topics, randomTopics }: InitialState = {}) => {
// console.log('using topics store')
if (topics) { if (topics) {
addTopics(topics) addTopics(topics)
} }
@ -114,7 +113,6 @@ export const useTopicsStore = ({ topics, randomTopics }: InitialState = {}) => {
} }
if (!randomTopicsStore) { if (!randomTopicsStore) {
randomTopicsStore = atom(randomTopics) randomTopicsStore = atom(randomTopics)
// console.log('random topics separate store')
} }
const getTopicEntities = useStore(topicEntitiesStore) const getTopicEntities = useStore(topicEntitiesStore)

View File

@ -10,9 +10,12 @@ import { getLogger } from './logger'
import reactionsForShouts from '../graphql/query/reactions-for-shouts' import reactionsForShouts from '../graphql/query/reactions-for-shouts'
import mySession from '../graphql/mutation/my-session' import mySession from '../graphql/mutation/my-session'
import { privateGraphQLClient } from '../graphql/privateGraphQLClient' import { privateGraphQLClient } from '../graphql/privateGraphQLClient'
import authLogout from '../graphql/mutation/auth-logout' import authLogoutQuery from '../graphql/mutation/auth-logout'
import authLogin from '../graphql/query/auth-login' import authLoginQuery from '../graphql/query/auth-login'
import authRegister from '../graphql/mutation/auth-register' import authRegisterMutation from '../graphql/mutation/auth-register'
import authCheckEmailQuery from '../graphql/query/auth-check-email'
import authConfirmCodeMutation from '../graphql/mutation/auth-confirm-email'
import authSendLinkMutation from '../graphql/mutation/auth-send-link'
import followMutation from '../graphql/mutation/follow' import followMutation from '../graphql/mutation/follow'
import unfollowMutation from '../graphql/mutation/unfollow' import unfollowMutation from '../graphql/mutation/unfollow'
import articlesForAuthors from '../graphql/query/articles-for-authors' import articlesForAuthors from '../graphql/query/articles-for-authors'
@ -25,10 +28,6 @@ import authorsAll from '../graphql/query/authors-all'
import reactionCreate from '../graphql/mutation/reaction-create' import reactionCreate from '../graphql/mutation/reaction-create'
import reactionDestroy from '../graphql/mutation/reaction-destroy' import reactionDestroy from '../graphql/mutation/reaction-destroy'
import reactionUpdate from '../graphql/mutation/reaction-update' import reactionUpdate from '../graphql/mutation/reaction-update'
import authCheck from '../graphql/query/auth-check'
import authReset from '../graphql/mutation/auth-reset'
import authForget from '../graphql/mutation/auth-forget'
import authResend from '../graphql/mutation/auth-resend'
import authorsBySlugs from '../graphql/query/authors-by-slugs' import authorsBySlugs from '../graphql/query/authors-by-slugs'
import incrementView from '../graphql/mutation/increment-view' import incrementView from '../graphql/mutation/increment-view'
@ -39,6 +38,36 @@ const REACTIONS_PAGE_SIZE = 100
const DEFAULT_RANDOM_TOPICS_AMOUNT = 12 const DEFAULT_RANDOM_TOPICS_AMOUNT = 12
export const apiClient = { export const apiClient = {
// auth
authLogin: async ({ email, password }) => {
const response = await publicGraphQLClient.query(authLoginQuery, { email, password }).toPromise()
return response.data.signIn
},
authRegiser: async ({ email, password }) => {
const response = await publicGraphQLClient.query(authRegisterMutation, { email, password }).toPromise()
return response.data.registerUser
},
authSignOut: async () => {
const response = await publicGraphQLClient.query(authLogoutQuery, {}).toPromise()
return response.data.signOut
},
authCheckEmail: async ({ email }) => {
// check if email is used
const response = await publicGraphQLClient.query(authCheckEmailQuery, { email }).toPromise()
return response.data.isEmailUsed
},
authSendLink: async ({ email }) => {
// send link with code on email
const response = await publicGraphQLClient.query(authSendLinkMutation, { email }).toPromise()
return response.data.reset
},
authConfirmCode: async ({ code }) => {
// confirm email with code from link
const response = await publicGraphQLClient.query(authConfirmCodeMutation, { code }).toPromise()
return response.data.reset
},
getTopArticles: async () => { getTopArticles: async () => {
const response = await publicGraphQLClient.query(articlesTopRated, { limit: 10, offset: 0 }).toPromise() const response = await publicGraphQLClient.query(articlesTopRated, { limit: 10, offset: 0 }).toPromise()
return response.data.topOverall return response.data.topOverall
@ -150,40 +179,6 @@ export const apiClient = {
return response.data.unfollow return response.data.unfollow
}, },
// auth
signIn: async ({ email, password }) => {
const response = await publicGraphQLClient.query(authLogin, { email, password }).toPromise()
return response.data.signIn
},
signUp: async ({ email, password }) => {
const response = await publicGraphQLClient.query(authRegister, { email, password }).toPromise()
return response.data.registerUser
},
signOut: async () => {
const response = await publicGraphQLClient.query(authLogout, {}).toPromise()
return response.data.signOut
},
signCheck: async ({ email }) => {
// check if email is used
const response = await publicGraphQLClient.query(authCheck, { email }).toPromise()
return response.data.isEmailUsed
},
signReset: async ({ email }) => {
// send reset link with code on email
const response = await publicGraphQLClient.query(authForget, { email }).toPromise()
return response.data.reset
},
signResend: async ({ email }) => {
// same as reset if code is expired
const response = await publicGraphQLClient.query(authResend, { email }).toPromise()
return response.data.resend
},
signResetConfirm: async ({ code }) => {
// confirm reset password with code
const response = await publicGraphQLClient.query(authReset, { code }).toPromise()
return response.data.reset
},
getSession: async () => { getSession: async () => {
// renew session with auth token in header (!) // renew session with auth token in header (!)
const response = await privateGraphQLClient.mutation(mySession, {}).toPromise() const response = await privateGraphQLClient.mutation(mySession, {}).toPromise()
@ -247,7 +242,7 @@ export const apiClient = {
}) })
.toPromise() .toPromise()
return response.data.reactionsByShout return response.data?.reactionsByShout
}, },
getAuthorsBySlugs: async ({ slugs }) => { getAuthorsBySlugs: async ({ slugs }) => {
const response = await publicGraphQLClient.query(authorsBySlugs, { slugs }).toPromise() const response = await publicGraphQLClient.query(authorsBySlugs, { slugs }).toPromise()

View File

@ -30,12 +30,12 @@ async function handle(req, res) {
} }
const server = createServer((req, res) => { const server = createServer((req, res) => {
handle(req, res).catch((err) => { handle(req, res).catch((error) => {
console.error('[ssr] server error', err); console.error('[ssr] server error', error);
res.writeHead(500, { res.writeHead(500, {
'Content-Type': 'text/plain', 'Content-Type': 'text/plain',
}); });
res.end(err.toString()); res.end(error.toString());
}); });
}); });