11<script setup lang="ts">
22import { useAtproto } from ' ~/composables/atproto/useAtproto'
33import { authRedirect } from ' ~/utils/atproto/helpers'
4+ import { ensureValidAtIdentifier } from ' @atproto/syntax'
45
56const handleInput = shallowRef (' ' )
7+ const errorMessage = shallowRef (' ' )
68const route = useRoute ()
79const { user, logout } = useAtproto ()
810
@@ -13,26 +15,41 @@ const localeSubPath = ['ko', 'pt', 'ja'].includes(currentLang) ? currentLang : '
1315const atprotoLink = ` https://atproto.com/${localeSubPath } `
1416
1517async function handleBlueskySignIn() {
16- await authRedirect (' https://bsky.social' , { redirectTo: route .fullPath })
18+ await authRedirect (' https://bsky.social' , { redirectTo: route .fullPath , locale: locale . value })
1719}
1820
1921async function handleCreateAccount() {
20- await authRedirect (' https://npmx.social' , { create: true , redirectTo: route .fullPath })
22+ await authRedirect (' https://npmx.social' , {
23+ create: true ,
24+ redirectTo: route .fullPath ,
25+ locale: locale .value ,
26+ })
2127}
2228
2329async function handleLogin() {
2430 if (handleInput .value ) {
25- await authRedirect (handleInput .value )
31+ // URLS to PDSs are valid for oauth redirects
32+ if (! handleInput .value .startsWith (' https://' )) {
33+ try {
34+ ensureValidAtIdentifier (handleInput .value )
35+ } catch (error ) {
36+ errorMessage .value =
37+ error instanceof Error ? error .message : $t (' auth.modal.default_input_error' )
38+ return
39+ }
40+ }
41+ await authRedirect (handleInput .value , {
42+ redirectTo: route .fullPath ,
43+ locale: locale .value ,
44+ })
2645 }
2746}
2847
2948watch (handleInput , newHandleInput => {
49+ errorMessage .value = ' '
3050 if (! newHandleInput ) return
3151
32- const normalized = newHandleInput
33- .trim ()
34- .toLowerCase ()
35- .replace (/ [^ a-z0-9 . -] / g , ' ' )
52+ const normalized = newHandleInput .trim ().toLowerCase ().replace (/ @/ g , ' ' )
3653
3754 if (normalized !== newHandleInput ) {
3855 handleInput .value = normalized
@@ -81,6 +98,9 @@ watch(handleInput, newHandleInput => {
8198 v-bind =" noCorrect"
8299 class =" w-full px-3 py-2 font-mono text-sm bg-bg-subtle border border-border rounded-md text-fg placeholder:text-fg-subtle transition-colors duration-200 hover:border-fg-subtle focus:border-accent focus-visible:(outline-2 outline-accent/70)"
83100 />
101+ <p v-if =" errorMessage" class =" text-red-500 text-xs mt-1" role =" alert" >
102+ {{ errorMessage }}
103+ </p >
84104 </div >
85105
86106 <details class =" text-sm" >
0 commit comments